PHP ini_set max_execution_time nog是否正常工作?

时间:2017-09-26 07:21:47

标签: php execution-time ini-set

要监控特定脚本的max_execution_time,请使用

ini_set('max_execution_time', 600); //600 seconds = 10 minutes

在我的脚本顶部。但是,当我构建同一文件的日志记录时,它会返回以下内容:

25-09-2017 23:08:01|STARTED
25-09-2017 23:09:01|ALREADY RUNNING
25-09-2017 23:10:01|ALREADY RUNNING
...................|ALREADY RUNNING
26-09-2017 01:09:01|ALREADY RUNNING
26-09-2017 01:10:01|ALREADY RUNNING
26-09-2017 01:11:01|STARTED
26-09-2017 01:12:01|ALREADY RUNNING
26-09-2017 01:13:01|ALREADY RUNNING
...................|ALREADY RUNNING
26-09-2017 03:10:01|ALREADY RUNNING
26-09-2017 03:11:01|ALREADY RUNNING
26-09-2017 03:12:01|STARTED
26-09-2017 03:13:01|ALREADY RUNNING
26-09-2017 03:14:02|ALREADY RUNNING
...................|ALREADY RUNNING
26-09-2017 05:09:01|ALREADY RUNNING
26-09-2017 05:10:02|ALREADY RUNNING
26-09-2017 05:11:01|STARTED
26-09-2017 05:12:01|ALREADY RUNNING
26-09-2017 05:13:02|ALREADY RUNNING
26-09-2017 05:14:01|ALREADY RUNNING
...................|ALREADY RUNNING
26-09-2017 07:14:01|ALREADY RUNNING
26-09-2017 07:15:01|ALREADY RUNNING
26-09-2017 07:16:01|STARTED

...................|ALREADY RUNNING表示中间每分钟重复的多条消息。

我做错了什么,因为到目前为止间隔不是10分钟?

编辑:

我有的while循环:

while (true) {
    //DO PROCESSING WHEN FILES ARE PRESENT
    Sleep(1);
    }

1 个答案:

答案 0 :(得分:1)

只需手动检查执行时间。

$max_exec_time = 600;

$start_time = time();
while (true) {
  do_something();
  sleep(1);
  if (time() - $start_time > $max_exec_time) {
    exit;
  }
}