On Thu, Dec 3, 2009 at 9:53 AM, Jordan Schatz <[email protected]> wrote: > I was wondering if anyone could enlighten me about what is the best > practice on forking a script's execution when it is running under Apache? I > have looked online and it seems that I should not use pcntl_fork if I am > running under Apache. which makes sense since Apache will be trying to > manage forking PHP to handle multiple requests... > > Mostly I want to fork to handle loging, in particular I want to send a > text message every time a particular page is loaded. I don't want the > page load to have to wait for the function to log in to the phone > gataway, send the text, and get confirmation, before it finishes sending > the page.
There are numerous systems for processing data asynchronously, usually focused on allowing services to scale for lots of requests & data. In this case though you are probably looking for something fairly simple, I'd outline it like: - Page request - Insert unprocessed async data (logging info in this case) into DB - Finish page request Then have a separate scheduled process look for async data that needs to be processed (say every 5 minutes). If the async data needs to be processed right away then you could switch from a scheduled method to adding a step before finishing the page request, that would fire off a program to process the async data. That program would return right away (so that it doesn't delay the page request) and process the data in the background. In general this approach allows you to do additional work, with the only expense to the page request being one additional insert into the DB. -- Joseph Scott [email protected] http://josephscott.org/ _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
