Linux下运行php5后台进程 [英] Running a php5 background process under Linux

查看:56
本文介绍了Linux下运行php5后台进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于这个主题有几个条目,例如 此处​​输入,但没有建议似乎确实有效.我这里有一个例子:

There are several entries on this subject, for example here and enter, but none of the suggestion does seem to work. I have an example here:

$pid = shell_exec("nohup sleep 10 2> /dev/null & echo $!");
echo $pid;

我希望在后台启动一个新命令 sleep 10 并立即返回到 shell.但发现的行为是此代码等待"子命令 <​​code>sleep 10 的执行.

which I expect to start a new command sleep 10 in the background, and return immediately to the shell. But the found behavior is that this code 'waits' for the execution of the subcommand sleep 10.

如何在后台将我的命令作为新进程运行?

How can I run my commad in the background as a new process?

推荐答案

根据的一些注释nohup 在维基百科页面上,一些 shell 拒绝关闭,除非所有流再次空闲.

According to some notes to nohup on the wikipedia page, some shells deny to close unless all streams are free again.

因此,一种解决方法是重定向所有三个标准流:输出、错误和输入,如下例所示:

A workaround therefore is to redirect all three standard streams: output, error and input, like in the following example:

nohup ./myprogram > foo.out 2> foo.err < /dev/null &

这只是一个猜测,但在您的场景中可能就是这种情况.

It is merely a guess, but that could probably be the case in your scenario.

$pid = shell_exec("nohup sleep 10 > /dev/null 2> /dev/null < /dev/null & echo $!");
echo $pid;

您可能想尝试一下.我希望这会有所帮助,即使它没有回答您的问题.

You might want to give this a try. I hope this is helpful even in case it does not answer your question.

这篇关于Linux下运行php5后台进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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