Shell_exec php 与 nohup
我认为类似的帖子有很多,但在搜索后我还没有找到解决方案。
基本上,我试图在后台运行两个脚本。当我在命令行中运行它们时,我在调用第一个脚本后看到:
/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 命令,但似乎没有任何效果。我怀疑忽略输入
位造成了困难,但我不确定。不管怎样,下面的方法是行不通的。它只是挂在浏览器中:
$output = shell_exec('/usr/bin/nohup php script.php > /dev/null &');
$output = shell_exec('/usr/bin/nohup php script2.php > /dev/null &');
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 $!
I've tried ...script.php > /dev/null &
with the same result. I get:
/usr/bin/nohup: ignoring input and redirecting stderr to stdout
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 $!
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 &');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试:
或:
Try:
Or:
这应该有效:
This shoul work:
首先将 php 命令放入 shell 文件脚本中,例如 myscript.sh:
使用 myscript.sh 运行 nohup:
使用 ps 验证:
First put your php command in a shell file script, e.g. myscript.sh:
Run nohup with myscript.sh:
Verify with ps: