NYCPHP Meetup

NYPHP.org

[nycphp-talk] background processes (was: building an 1-way email list manager)

Dan Cech dcech at phpwerx.net
Tue Nov 15 09:41:29 EST 2005


Hans,

I for one would be very interested in a more in-depth discussion on this 
subject, as it sounds like there is a lot more to it than I was aware.

Dan

Hans Zaunere wrote:
 >
 > Anthony Papillion wrote on Tuesday, November 15, 2005 4:31 AM:
 >> This discussion triggers a question that I'm sure someone here can
 >> answer: wouldn't forking the script to the background allow one to
 >> send a huge volume of email without a timeout?
 >
 > It would, but forking can be a bit of an art.
 >
 > For any long running process that you wish to spawn out of PHP 
running under
 > Apache (as a DSO anyway) you need to cut ties with Apache.  When a 
fork() is
 > done, the file descriptors are copied as well, meaning that now your PHP
 > script is sharing stdout/stdin/stderr with Apache.  The implication 
of this
 > is that your script is now waiting for input/output just like Apache, and
 > more importantly, Apache is waiting for your script.
 >
 > So in order to correctly - and completely - fork, you need to fork(), 
kill
 > child, fork() again (creating a new process group), and most importantly,
 > close and reopen file descriptors in the PHP process.  How to do this
 > correctly varies a little between flavors of Linux/BSD/etc.
 >
 >
 > ---
 > Hans Zaunere / President / New York PHP
 >    www.nyphp.org  /  www.nyphp.com




More information about the talk mailing list