为什么这个进程不在后台运行? [英] Why this process is not running in background?
问题描述
所以基本上我想运行可以生成大约 15k pdf 文件的脚本,并且由于 php max_timeout 需要从 shell 中完成...
So basically i want to run script that will make around 15k pdf files, and it needs to be done from shell because of php max_timeout...
服务器:Ubuntu 10.04.1PHP : 5.3.2-1ubuntu4.5
Server: Ubuntu 10.04.1 PHP : 5.3.2-1ubuntu4.5
所以我目前尝试过:
function run_in_background($Command){
$ps = shell_exec("nohup php5 $Command > /dev/null 2> /dev/null & echo $!");
return $ps;
}
$ok = run_in_background('/var/www/custom/web/public/make_pdf.php');
if(!empty($ok))
var_dump($ok);
else
exit('Fail');
在那之后我去ssh控制台并执行ps $ps
,作为回应,我只得到没有信息的标题 - 巫婆意味着进程没有运行......
And after that i go to ssh console and do ps $ps
and in response i get headers only with no info - witch means process is not running...
我如何才能做到这一点?
How can i do this so it works?
推荐答案
尝试不使用 echo $!
或以 &
结尾.如果要运行 2 个内联"过程,请使用 &&
而不是简单的 &
.
Try without echo $!
or ending with &
. If you want to run 2 proccess 'inline', use &&
instead of a simple &
.
示例:nohup php5 $Command >/dev/null 2>/dev/null &&回声 $!&
要检查过程是否以错误结束,请执行以下操作:
To check if the proccess end with error do this:
nohup php5 $Command >command_stout.txt 2>command_stderr.txt &&回声 $!&
这篇关于为什么这个进程不在后台运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!