Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

You want to run application in background and forget?

there are many posts regarding this on

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".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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