NYCPHP Meetup

NYPHP.org

[nycphp-talk] building an 1-way email list manager

Hans Zaunere lists at zaunere.com
Tue Nov 15 09:19:16 EST 2005



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