0

この回答について質問があります phpはバックグラウンドプロセスを実行します

誰かが私に答えが説明することを試すための実用的な簡単な例を提供できますか?

前もって感謝します!

アルベルト

4

1 に答える 1

2

Linux ボックスのみ:

結果.php

<?php
$cmd = 'for i in {1..5}; do date; sleep 2; done';
$outputfile = '/tmp/result.txt';
$pidfile = '/tmp/result.pid';
exec(sprintf("%s > %s 2>&1 & echo $! >> %s", $cmd, $outputfile, $pidfile));
?>

コマンドラインで:

php result.php;
tail /tmp/result.txt; /* to monitor the results, take 10 seconds to complete */
cat /tmp/result.pid   /* the pid registered */
于 2010-12-16T16:34:13.107 に答える