Not sure if this is more appropriate for Server Fault or Stack Overflow, but here goes.

I'm using mod_php on Apache MPM prefork and spawning a new process like-so:

exec("/usr/bin/php -f backgroundScript.php &");

Assuming that the new backgroundScript.php child process runs for a long time…

1) Is the parent PHP process now considered idle? Does it return to the server pool?

2) If Apache does kill the parent PHP process to return to MinSpareServers, will backgroundScript.php also get cleaned-up or continue running indefinitely?

3) Are there other ways that Apache may inadvertently kill the backgroundScript.php child process? service httpd stop perhaps?


1 Answer 1


You want to run application in background and forget?

there are many posts regarding this on php.net

Also, note from the exec man:


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.

same here and here and here etc

I've got ugly code, violating these rules:

echo "pre";
exec("someuglylongandworkingthingwithoutput &");
echo "post";

Just tested on my fedora box with default apache+php (prefork + module), i've killed processes with killall -9 /usr/sbin/httpd

  1. despite & - no, didn't, it's still considered as running. my background app is still running
  2. according to my test above - it will continue
  3. depends how init script terminates apache, same according to p 1.

After adding /dev/null - everything's fine, parent process id is "1".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.