PHP Exec:不等待,不丢弃输出,不up


PHP Exec: Without Waiting, Without Discarding the Output, Without nohup

我需要在PHP中运行这样的命令:

exec('dosomething > saveit.txt');

但是我不希望PHP等待它完成。我也不想丢掉输出,我也不想使用nohup,因为我要将它用于同一目录下的其他内容。

我也试过pclose(popen('dosomething > saveit.txt','r'));,没有工作,它仍然等待。

在命令末尾添加&号,因此:

exec('dosomething > saveit.txt &');

exec()的文档中有一个有趣的注释说:

花了很长时间才想出我接下来要发表的文章。如果希望在后台执行命令,而不让脚本等待结果,则可以执行以下操作:

 <?php
  passthru("/usr/bin/php /path/to/script.php ".$argv_parameter." >> /path/to/log_file.log 2>&1  &");
 ?>