Forum Moderators: coopster

Message Too Old, No Replies

daemon process (PHP)

limitting the amount of children (PHP)

         

nosanity

10:27 pm on Apr 3, 2003 (gmt 0)

10+ Year Member



How could you possibly limit the number of children you spawn from the parent process... I am using a mysql database to check for new results, then spawning a child based on that.. the child will exit by itself. How can I limit the number of children it will spawn from unlimited to lets say 10...

noSanity

andreasfriedrich

2:24 am on Apr 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is that ten children running concurrently or a total of ten children ever?

If you want only ten concurrently running children then keep a variable which stores the number of alive children. Increase that number when you successfully pcntl_fork [php.net] a new child.

To keep track of died children and reap´em when they die - as any good parent will do - use pcntl_signal [php.net] to install a SIGCHLD handler which will reap your children.

In that reaper function loop while pcntl_waitpid [php.net] is true. Make sure that you use -1 for the PID parameter which will wait for any children and WNOHANG as the options parameter to return immediately if there are no dead children to reap. In that loop decrease your number of running children by one.

Andreas

nosanity

8:03 am on Apr 4, 2003 (gmt 0)

10+ Year Member



Perfect... man I oughta kiss you... but instead I owe u a beer or 10. ;)

Thanks,

J.