Shell_exec PHP与Nohup [英] Shell_exec php with nohup

查看:220
本文介绍了Shell_exec PHP与Nohup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为有很多类似的帖子,但搜索后仍未找到解决方案.

I think there are tons of similar posts but I haven't yet found a solution after searching around.

基本上,我正在尝试在后台运行两个脚本.当我在命令行中运行它们时,我在调用第一个脚本后会看到:

Basically, I'm trying to run two scripts in the background. When I run them in the commandline, I see after calling my first script:

/usr/bin/nohup php script.php > nohupoutput.log & echo $!

我尝试过...script.php > /dev/null &的结果相同.我得到:

I've tried ...script.php > /dev/null & with the same result. I get:

/usr/bin/nohup: ignoring input and redirecting stderr to stdout

我忽略并运行第二个.我注意到它似乎挂在那里了,按 Enter 使我回到machine:~folder>

which I ignore and run the second one. I noticed that it seemed to be hanging there, and pressing Enter brought me back to machine:~folder>

/usr/bin/nohup php script2.php > nohupoutput.log & echo $!

两个脚本都可以工作.我试图将其转换为shell_exec命令,但似乎没有任何效果.我怀疑ignoring input位引起了麻烦,但是我不确定.无论如何,以下操作无效.它只是挂在浏览器中:

Both scripts work. I tried to then convert this to a shell_exec command and nothing seems to work. I suspect that the ignoring input bit is causing difficulties, but I'm not sure. Regardless, the following does not work. It just hangs in the browser:

$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 &');

这篇关于Shell_exec PHP与Nohup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆