PHP脚本永远运行,忽略max_execution_time

时间:2013-09-13 12:26:17

标签: php execution-time

以下脚本监视文件夹/dev/shm/test并实时输出任何创建的文件:

<?php
$descriptorspec = array(
  0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
  1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
  2 => array("pipe", "a") // stderr is a file to write to
);

$cwd = '/tmp';
$env = array('some_option' => 'aeiou');

$process = proc_open('inotifywait -mc -e create /dev/shm/test/', $descriptorspec, $pipes, $cwd, $env);

if (is_resource($process)) {

  header("Content-type: text/html;charset=utf-8;");
  ob_end_flush(); //ends the automatic ob started by PHP
  while ($s = fgets($pipes[1])) {
    print $s;
    flush();
  }
  fclose($pipes[1]);
  fclose($pipes[0]);
  fclose($pipes[2]);

  // It is important that you close any pipes before calling
  // proc_close in order to avoid a deadlock
  $return_value = proc_close($process);

  echo "command returned $return_value\n";
}
?>

问题是它永远不会结束,永远运行。关于为什么会发生这种情况的任何线索?我在php.ini中有max_execution_time = 30

如何监控此脚本使用的资源数量?

非常感谢。

2 个答案:

答案 0 :(得分:0)

max_execution_time定义允许脚本运行的实际时间,因此这不包括在脚本执行之外花费的任何时间,即使它是由它触发的:数据库查询,文件系统轮询,网络等。

解决方案是使用inotifywait的-t <seconds>, --timeout <seconds>选项。

答案 1 :(得分:-1)

max_execution_time仅影响在线执行。基于CLI的脚本永远运行

相关问题