nohup的:在后台运行PHP程序 [英] nohup: run PHP process in background

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

问题描述

我尝试在后台运行PHP的进程和从php文件启动这一点。

i try to run php processes in background and start this from an php file.

一些信息:PHP 5.2.17版本,PHP safe_mode设置为关闭,linux系统。我开始以exec的过程中,已经尝试了shell_exec。我的所有文件设置为0755,0777。

Some informations: PHP Version 5.2.17, php safe_mode is off, linux system. I start the process with exec, tried already shell_exec. I set all files to 0755, 0777.

$pid = exec("nohup $cmd > /dev/null 2> /dev/null & echo $!");

如果我打印这一说法,我得到这个和PID是好的:

If i print this statement, i get this and the pid is okay:

nohup /usr/local/bin/php5 /.../../file.php > /dev/null 2> /dev/null & echo $!

如果我找下SSH与流程

If i look for processes under ssh with

top

我看到我用正确的PID php5的过程。是root用户

i see my php5 process with the correct pid. user is root

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                      
 3533 xxxxxxxx  20   0 21356 8868 4580 S    0  0.4   0:00.13 php5                                                                                          
 3536 xxxxxxxx  20   0 20836 8260 4428 S    0  0.4   0:00.09 php5                                                                                          
 3539 xxxxxxxx  20   0 20836 8260 4428 S    0  0.4   0:00.09 php5                                                                                          
 3542 xxxxxxxx  20   0 20836 8260 4428 S    0  0.4   0:00.09 php5                                                                                          
 3545 xxxxxxxx  20   0 20836 8260 4428 S    0  0.4   0:00.09 php5                                                                                          
 3548 xxxxxxxx  20   0 20836 8260 4428 S    0  0.4   0:00.09 php5                                                                                          
 3551 xxxxxxxx  20   0 20836 8260 4428 S    0  0.4   0:00.09 php5    

如果我开始处理人工上部看起来像这样:

if i start the process manual top looks like this:

PID  USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND 
8141 xxxxxxxx  22   2 24048 9.9m 5344 S   10  0.5   0:00.31 php5 

问题:
好像也没什么happens.To调试一点点我在文件中写了一个输出

The problem: it seems like nothing happens.To debug a little bit i wrote a output in the file

ob_start();
echo "STARTING...";
writeLog(ob_get_contents());
//...
function writeLog($info){
    $handle = fopen("file.log", "a+");
    fwrite($handle, $info);
    fclose($handle);
} 
exit;

在我的文件中没有记录。如果我在浏览器中启动该文件,它会正确地处理,让我file.log的调试的信息。

No logs in my file. If I start this file in my browser, it processes correctly and get my file.log with the "debugging" information.

为什么这是工作在浏览器中,而不是在EXEC /指挥了shell_exec ??!我有完全正确的使用这些PID PHP进程,但没有结果。

Why this is working in browser and not on exec/shell_exec command??! i have exactly these php processes with correct pid, but no result.

非常感谢你的帮助!

推荐答案

在PHP CLI环境可以从网络环境(mod_php,并且FCGI,等等)不同。这是完全可能的脚本与错误从命令行运行时死亡,而不是当你调用它通过一个网络服务器。调试脚本。如果可以的话,SSH到服务器,苏到Web服务器的用户和运行命令行自己的脚本。

The PHP CLI environment can be different from the web environment (mod_php, FCGI, whatever). It's entirely possible for a script to die with an error when run from the commandline and not when you invoke it through a webserver. Debug your script. If you can, SSH into your server, su to the webserver user and run the script from the commandline yourself.

如果你不能做到这一点,建立自己的开发服务器,在那里你可以做到这一点(这并不难,如果你知道一些Linux)。

If you can't do that, set up your own development server where you can do this (it's not that hard if you know some Linux).

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

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