我认为有很多类似的帖子,但我在四处搜索后还没有找到解决方案。
基本上,我试图在后台运行两个脚本。当我在命令行中运行它们时,我在调用我的第一个脚本后看到:
/usr/bin/nohup php script.php > nohupoutput.log & echo $!
我试过 ...script.php >/dev/null &
得到了同样的结果。我得到:
/usr/bin/nohup: ignoring input and redirecting stderr to stdout
我忽略并运行第二个。我注意到它似乎卡在那里,然后按 Enter 将我带回 machine:~folder>
/usr/bin/nohup php script2.php > nohupoutput.log & echo $!
两个脚本都有效。然后我尝试将其转换为 shell_exec 命令,但似乎没有任何效果。我怀疑 ignoring input
位造成了困难,但我不确定。无论如何,以下内容不起作用。它只是卡在浏览器中:
$output = shell_exec('/usr/bin/nohup php script.php > /dev/null &');
$output = shell_exec('/usr/bin/nohup php script2.php > /dev/null &');
最佳答案
尝试:
$output = shell_exec('/usr/bin/nohup php script.php >/dev/null 2>&1 &');
或者:
exec('/usr/bin/nohup php script.php >/dev/null 2>&1 &');
关于php - 带 nohup 的 Shell_exec php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4929827/