exec - PHP background process with && in command -


i'm aware can run background process following:

exec("dotask.php $arg1 $arg2 $arg3 >/dev/null 2>&1 &"); 

(taken from: run php task asynchronously)

however have script depends on status of first execution. example:

mongoexport ... | awk ... > my.csv && zip myzip my.csv 

the csv file must exists before can zip.
update: filename , few query conditions user submitted values.

so have like:

exec("mongoexport ... | awk ... > my.csv && zip myzip my.csv > /dev/null 2>&1 &); 

but doesn't work. php hangs there waiting script finish running.

i tried

exec("mongoexport ... | awk ... > my.csv &); 

that works.

so && reason doesn't run in background?
how can make example run in background?

the following work

exec("(mongoexport ... | awk ... > my.csv && zip myzip my.csv) > /dev/null 2>&1 &") 

it tells shell run sequence of commands enclosed in braces in background process , redirect output, exec function has nothing wait for.

in example, shell launched exec waited awk finish , after ran zip in background (if awk exited status 0)


Comments