0

以下脚本监视文件夹/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";
}
?>

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

如何监控此脚本使用了多少资源?

非常感谢。

4

2 回答 2

0

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

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

于 2013-09-13T12:30:06.047 回答
-1

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

于 2013-09-13T12:29:46.717 回答