PHP执行时间-防止Apache停止脚本


PHP execution time - prevent Apache from stopping script

我正试图让一个PHP脚本在本地Linux Apache下运行,而不会被Apache阻止。我使用的是PHP 5.5.9-1ubuntu4.4Apache/2.4.7 (Ubuntu)Ubuntu 14.04 LTS 64-bit。到目前为止我做了什么:

在我的PHP脚本中:

ignore_user_abort(true);
set_time_limit(0);
...
foreach(...) {
    ...
    // inside loop
    usleep(1000);
    ...
}

在所有php.ini:中

max_execution_time=3600;

以上这些都无济于事。脚本在大约30秒后停止。我没有主意。我的脚本可能因为内存不足而被关闭吗?最好的检查方法是什么?

编辑:

通过添加"ini_set('display_errors',1);",我得到了错误Allowed memory size of 134217728 bytes exhausted。所以这是关于记忆的,谢谢你的提示如何检查。

解决方案:

根本的问题是"foreach"循环的使用。将所有"foreach"循环切换为"for"循环后,内存使用变得更加稳定。

ini_set("max_execution_time",0)
仅在http中,如果使用https,则必须更改php.ini
请记住重新加载您的web服务器。

要查看是什么导致脚本停止,请在页面顶部添加以下内容:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
?>