【问题标题】:php's set_time_limit(0) hangs and throws HTTP 500php 的 set_time_limit(0) 挂起并抛出 HTTP 500
【发布时间】:2017-12-24 12:45:26
【问题描述】:

这个简单的测试,调用 set_time_limit 10 次:

<?php
echo("<html><head><title>set_time test</title></head><body><h1>set_time test</h1>");
for ($i=0; $i<10; $i++) {
    error_log("Round $i");
    set_time_limit(0); echo("<p>$i</p>");
}
echo("</body></html>");

永远挂起错误:

 // Fatal error: Maximum execution time of 30 seconds exceeded in .../_set_time.php on line 4
 // Call Stack:
 //   0.0007 231768 1. {main}() .../_set_time.php:0
 //   0.0007 232000 2. set_time_limit() .../_set_time.php:4

30 秒是php.inimax_execution_time 的值。如果我把它提高到 3000,脚本就会继续旋转。我在 apache 的配置中为文档根目录设置了 AllowOverrideAll(假设它很重要 - 它不应该,但仍然)

类似的机器(相同的操作系统和软件版本,配置非常接近)每次都完美地运行脚本。日志文件什么也不显示。谷歌搜索大多是默默无闻或无关紧要的。似乎有些奇怪的系统/配置怪癖。

想法?

操作系统:CentOS 6.9
阿帕奇 2.2.15
php 5.6 (webtatic RPM:php56w-5.6.30-1.w6.x86_64)

编辑:作为bug提交到xdebug项目:https://bugs.xdebug.org/view.php?id=1457

【问题讨论】:

  • 抛出的错误是什么?这看起来像你的代码进入一个无限循环......
  • 无需调用 set_time_limit(0);到for循环上。只需将其设置为您脚本的第一行。它会将您的脚本时间限制设置为无限。
  • 错误(如帖子所示)是超出执行时间 - 但如前所述,在 php.ini 中提高执行时间只会使其永远挂起,主要是在第一次调用 set_time_limit 时。循环运行(当它运行时)10 次($i

标签: php linux apache centos


【解决方案1】:

好的,罪魁祸首是 xdebug 扩展(安装在一台机器上,但没有安装在另一台机器上)。通过删除它(php56w-pecl-xdebug-2.5.3-1.w6.x86_64),不需要的行为消失了。有点棘手,从缩小到 set_time_limit 到找到负责任的扩展,花了 2 天多的时间来确定。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 2012-08-13
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 2015-05-02
    相关资源
    最近更新 更多