Tuesday, January 13, 2009

background process from symfony

I need to launch background processes when receiving a given type of requests in symfony. I went down the pcntl_fork road a bit, planning a classical fork/exec. But i found out that pcntl_fork is available on php client but Not on php appache2. Likely they dont want you to fork apache2 :)

The workaround i got is simply to do a exec of a little bash script and to fork in bash. system was causing issues with the output. The current version is along the line:

// build the cooked_cmdline
$cooked_cmdline = $cmdline.' >/dev/null 2>/dev/null & echo $!';
// execute the cooked cmdline
$pid_str = exec($cooked_cline, $retval);
// convert $pid_str into integer
$pid = (integer)$pid_str;

Rather ugly, i will likely post something better later.

Update: i made a plugin to handle this called sfWorkerPlugin.

0 comments:

Share/Save/Bookmark