php进程背景
关于这个答案我有个问题 有人能给我一个简单的例子来解释答案吗 提前谢谢 Alberto仅限linux机箱: result.phpphp进程背景,php,process,background-process,Php,Process,Background Process,关于这个答案我有个问题 有人能给我一个简单的例子来解释答案吗 提前谢谢 Alberto仅限linux机箱: 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
<?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));
?>
这个答案在除shell会话之外的任何上下文中都是错误的,并且失败是一种可能的结果——生成的进程没有与会话分离,它只是并行运行,直到会话结束。您确定这适用于您的场景吗?
php result.php;
tail /tmp/result.txt; /* to monitor the results, take 10 seconds to complete */
cat /tmp/result.pid /* the pid registered */