shell_exec()
PHP 組み込み Web サーバーは、バックグラウンド プロセスを適切に処理していないようです。でバックグラウンドに明示的に配置されていても、バックグラウンド プロセスが完了するまでリクエストはハングし&
ます。
例:
$ ls
runit.php
$ cat runit.php
<?php
echo "Here we are\n";
shell_exec("sleep 5 &");
echo "and the command is done\n";
?>
$ php -S localhost:7891
PHP 5.5.9-1ubuntu4.9 Development Server started at Mon May 18 19:20:12 2015
Listening on http://localhost:7891
Press Ctrl-C to quit.
次に、別のシェルで:
$ GET http://localhost:7891/runit.php
(...waits five seconds...)
Here we are
and the command is done
これは起こるべきではありませんし、実稼働グレードの Web サーバーを使用している場合は実際には起こりません。それを回避する方法はありますか?
(注: これはフラッシュの問題ではありません。flush()
最初のエコーの後に追加しても発生せず、バックグラウンド プロセスが完了するまでリクエストはハングします。)