James Nunnerley wrote:

I'm creating a search function as part of our webmail frontend, however I'm
having big problems with timeout etc.

What we'd like to do is run the actual search query in the background (i.e.
fork) while the viewable page shows a nice scrollie banner etc!

Due to various problems with the server we are using (Zeus) we can't just
run an exec().  I've had a look around, and it would seem that pcntl maybe
the way forward.

Does anyone have an example working script, or indeed a decent tutorial on
how to use the functionality?  The php manual has limited information on
using the functions, and I just can't get my head around how it's meant to
work?!!!
IMHO forking in response to a web request is a very very very bad idea(tm).

I had a similar problem a while back. I solved it by having a CLI process that watches a search queue table in the DB. When it sees an entry it kicks off another script to do the actual search. Meanwhile the frontend is using AJAX to display a progress bar using a percentage written to the search queue record by the searching process. Works very well for that site, although it has to be said it is not a particularly busy site so scalability has never been tested.

Using this method it's possible to restrict each session to a single search if needed since you can set a cancel flag in the search queue record which gets checked by the searching process. This particular site ties each search to the php session id.

HTH.

-Stut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to