Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php exec() background process issues

Tags:

php

exec

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

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

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

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

Any ideas?

like image 759
kylex Avatar asked Jan 28 '13 05:01

kylex


People also ask

How to run PHP process in background?

So, to run any background process from PHP, we can simply use either exec or shell_exec function to execute any terminal command and in that command, we can simply add & at the last so that, the process can run in the background.

How to use exec command in PHP?

echo "<pre>$output</pre>" ; ?> The exec() function is an inbuilt function in PHP which is used to execute an external program and returns the last line of the output. It also returns NULL if no command run properly.


1 Answers

Note:

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

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

so:

exec("php csv.php $file $user > /dev/null &"); // no $output
like image 162
Emery King Avatar answered Oct 07 '22 18:10

Emery King