douyaju4259 2012-09-16 23:50
浏览 126
已采纳

将内存设置为高,然后将set_time_limit设置为0

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)?

  • 写回答

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.

    Example:

    // 1. Script starts
    echo ini_get('memory_limit');//128M
    
    // 2. We set a new limit the script will now have 100M
    ini_set('memory_limit','100M');
    echo ini_get('memory_limit'); //100M
    
    die;
    // 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:

    for($i=0;$i<=10;$i++){
        set_time_limit(1);
        usleep(999998); //2micro seconds from a second
        echo $i;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站