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 = 30php.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 に答える