2012-09-16 23:50
浏览 126


In PHP if I set the the memory 100M via ini_set and then I set set_time_limit(0); Does that mean that my PHP memory allocation is 100M forever(Until I restart my Apache)?

图片转代码服务由CSDN问答提供 功能建议

在PHP中,如果我通过 ini_set 设置内存100M,然后设置 set_time_limit(0); 这是否意味着我的PHP内存分配永远是100M(直到我重启我的Apache)?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongzhi6927 2012-09-16 23:52

    No its reset back to the original at the end of script execution.

    From the manual:

    string ini_set ( string $varname , string $newvalue )

    Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

    and set_time_limit(0); is treated the same.


    // 1. Script starts
    echo ini_get('memory_limit');//128M
    // 2. We set a new limit the script will now have 100M
    echo ini_get('memory_limit'); //100M
    // 3. Script ends now its set back to 128M

    With set_time_limit(0); it just tells the script to not time out, tho say you were to use set_time_limit(0); within a loop then on each iteration its internal counter is set to 0 over and over.

    So if you were to use set_time_limit(1); within a loop as long as each iteration of the loop did not last longer then 1 second then it would still not time out as set_time_limit(n); would reset the internal timeout counter to 0 on each iteration.

    Example of it not timing out after 1 second:

        usleep(999998); //2micro seconds from a second
        echo $i;
    解决 无用
    打赏 举报

相关推荐 更多相似问题