lufficc
V2EX  ›  PHP

分享一片文章: Laravel 的核心概念,另请教 Php 大神。。。

  •  
  •   lufficc · Oct 13, 2016 · 3033 views
    This topic created in 3568 days ago, the information mentioned may be changed or developed.

    原文地址:Laravel 的核心概念

    我是个 Php 新手,所以请教一个问题:

    Php 的变量包括静态变量会在下一次请求时重新初始化,所有的变量在下一次请求都会被 unset,这句话对不对?

    13 replies    2016-10-14 12:52:43 +08:00
    neoblackcap
        1
    neoblackcap  
       Oct 13, 2016
    php 不是一个请求一个进程吗?
    lufficc
        2
    lufficc  
    OP
       Oct 13, 2016 via Android
    @neoblackcap 不一定吧
    guoer
        3
    guoer  
       Oct 13, 2016 via iPhone
    每个请求之间没关联。不同的生命周期
    lufficc
        4
    lufficc  
    OP
       Oct 13, 2016 via Android
    @guoer 知道了~~
    tinyhill
        5
    tinyhill  
       Oct 14, 2016
    对的,一个请求一个进程,但是 fpm 模型里进程是可以复用的。
    lufficc
        6
    lufficc  
    OP
       Oct 14, 2016 via Android
    @tinyhill 好像一般服务器都会对 php 进行优化,核心服务只需要启动一次就行了~~
    tinyhill
        7
    tinyhill  
       Oct 14, 2016
    @luffylcc 你所说的核心服务是指什么? php 一般是通过 fpm 提供 web 服务的,基本策略是维护一个 cgi 进程池,优化也只是在进程调度和资源管理方面。 php 是解释执行,即便能靠 opcache 提升性能,性能鸿沟跨不过去,这是机制所决定的。
    lufficc
        8
    lufficc  
    OP
       Oct 14, 2016
    @tinyhill 我的意思是 php.ini 的第三方扩展,他们应该是只需要启动一次。。。
    shiji
        9
    shiji  
       Oct 14, 2016
    PHP performs garbage collection at three primary junctures:

    When you tell it to
    When you leave a function
    When the script ends

    只要满足任意一个条件,就会被清理。
    跟哪种 SAPI 无关。
    跟加载的模块无关。

    如果你这问题里面不存在文字游戏的话,这句话就是对的。
    Nicksxs
        10
    Nicksxs  
       Oct 14, 2016
    @luffylcc 启动才加载,想多了
    ichou
        11
    ichou  
       Oct 14, 2016
    @luffylcc 你这个很好验证啊 先起 fpm, 然后在 php.ini 注释掉一个组件,再用探针去看这个组件还在不在,你就知道是不是只需要启动一次 😛
    lufficc
        12
    lufficc  
    OP
       Oct 14, 2016
    @ichou 厉害,谢谢
    lufficc
        13
    lufficc  
    OP
       Oct 14, 2016
    @shiji 没文字游戏,应该是对的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4335 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 10:10 · PVG 18:10 · LAX 03:10 · JFK 06:10
    ♥ Do have faith in what you're doing.