I am trying to run php processes in the background and run this from a php file.
Some information: PHP Version 5.2.17, php safe_mode off, Linux system. I start the process using exec, already tried shell_exec. I set all the files to 0755, 0777.
$pid = exec("nohup $cmd > /dev/null 2> /dev/null & echo $!");
If I print this expression, I get this, and pid is fine:
nohup /usr/local/bin/php5 /.../../file.php > /dev/null 2> /dev/null & echo $!
If I am looking for processes in ssh with
top
I see my php5 process with the correct pid. root user
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 run the top of the process manual, it 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
Problem: Nothing seems to be happening. To debug a bit, I wrote the output in a file
ob_start(); echo "STARTING..."; writeLog(ob_get_contents()); //... function writeLog($info){ $handle = fopen("file.log", "a+"); fwrite($handle, $info); fclose($handle); } exit;
There are no logs in my file. If I run this file in my browser, it correctly processes and receives the file.log file with the "debug" information.
Why does this work in the browser and not in the exec / shell_exec command ?! I have exactly these php processes with the correct pid, but there is no result.
Thank you for help!