Jochem Maas wrote:
Roman Neuhauser wrote:
The parent needs to wait(2) for its children. http://php.net/pcntl_wait
have I understood correctly that using pcntl_wait() means you can't do anything in
the parent process until all children are dead?
this seems strange. probably I'm mis-understanding and need to reread [alot of] stuff.
but if it is true how do you go about tackling the signal handling in child processes
AND at the same time have the parent process do something useful like ...
interact/direct child processes, do other management tasks whilst child processes are running?
maybe I'm misunderstanding the whole concept - it's nice to have that newbie feeling again ;-)
I have a system that forks to 'do work'. The main script sits in an
infinite loop waiting for work, when it gets some it forks to process it.
In that loop I have the following at the end...
while (pcntl_wait($status, WNOHANG)) > 0)
$workers--;
That takes care of cleaning up finished processes while running.
If the loop ends for any reason (e.g. it got stopped by a status
change), I do...
$started = time();
while ($workers > 0 and (time() - $started) < 300)
{
pcntl_wait($status, WNOHANG);
$workers--;
sleep(1);
}
That sits waiting for up to 5 minutes for all processes to end.
-Stut
**
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php