Problems with php exec () background process

I am trying to process a file in the background with the following command, but does nothing.

exec("php csv.php $file $user > /dev/null &", $output); 

If I delete > /dev/null & , then the file processes, but not in the background.

 exec("php csv.php $file $user", $output); 

Any ideas?

+8
php exec
source share
2 answers

Note:

If the program starts with this function so that it continues to work in the background, the output of the program should be redirected to a file or other output stream. Otherwise, PHP will hang until the program terminates.

http://php.net/manual/en/function.exec.php

So:

 exec("php csv.php $file $user > /dev/null &"); // no $output 
+15
source share

Have you considered screen usage? You can start a screen session that runs in a separate process. The output will go to a screen session, which you can reconnect to another terminal while it is still working.

 exec("screen -d -m -S my_php_session csv.php $file $user", $output); 
0
source share

All Articles