Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在 PHP 中运行这样的命令:
exec('dosomething > saveit.txt');
除了我不希望 PHP 等待它完成。我也不想丢弃输出,也不想使用 nohup,因为我将它用于同一目录中的其他内容。
我也试过pclose(popen('dosomething > saveit.txt','r'));了,还是不行,还在等。
pclose(popen('dosomething > saveit.txt','r'));
在命令末尾添加一个& 符号,因此:
exec('dosomething > saveit.txt &');
在文档中exec()有一条有趣的评论说:
exec()
花了很长时间才弄清楚我接下来要发布的线路。如果要在后台执行命令而不让脚本等待结果,可以执行以下操作:
<?php passthru("/usr/bin/php /path/to/script.php ".$argv_parameter." >> /path/to/log_file.log 2>&1 &"); ?>