开发者

php process background

开发者 https://www.devze.com 2023-01-31 11:45 出处:网络
I\'ve a question about this answer php execute a background process Can anyone provide me a working simple example to try what the answer explains?

I've a question about this answer php execute a background process

Can anyone provide me a working simple example to try what the answer explains?

Thanks in a开发者_如何学Pythondvance!

Alberto


On linux box only:

result.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));
?>

in command line:

php result.php;
tail /tmp/result.txt; /* to monitor the results, take 10 seconds to complete */
cat /tmp/result.pid   /* the pid registered */
0

精彩评论

暂无评论...
验证码 换一张
取 消