0

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

exec('dosomething > saveit.txt');

除了我不希望 PHP 等待它完成。我也不想丢弃输出,也不想使用 nohup,因为我将它用于同一目录中的其他内容。

我也试过pclose(popen('dosomething > saveit.txt','r'));了,还是不行,还在等。

4

2 回答 2

4

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

exec('dosomething > saveit.txt &');
于 2011-11-09T09:30:02.647 回答
3

在文档中exec()有一条有趣的评论说:

花了很长时间才弄清楚我接下来要发布的线路。如果要在后台执行命令而不让脚本等待结果,可以执行以下操作:

 <?php
  passthru("/usr/bin/php /path/to/script.php ".$argv_parameter." >> /path/to/log_file.log 2>&1  &");
 ?>
于 2011-11-09T09:34:17.980 回答