note 63594 added to function.pcntl-wait

From: Date: Fri, 24 Mar 2006 19:19:52 +0000
Subject: note 63594 added to function.pcntl-wait
Groups: php.notes 
Request: Send a blank email to php-notes+get-106541@lists.php.net to get a copy of this message
The code before isnt working for me cause the children are correctly started but not refreshed after they died. So keep in mind to use this instead and use the signal handler to know when a child exits to know when you have to start a new one. I added a few lines to the posting from {andy at cbeyond dot net} cause his post wasnt working for me as well (PHP5.1). Same effect like the one below. <?php declare(ticks = 1); $max=5; $child=0; // function for signal handler function sig_handler($signo) { global $child; switch ($signo) { case SIGCHLD: echo "SIGCHLD received\n"; $child--; } } // install signal handler for dead kids pcntl_signal(SIGCHLD, "sig_handler"); while (1){ $child++; $pid=pcntl_fork(); if ($pid == -1) { die("could not fork"); } else if ($pid) { // we are the parent if ( $child >= $max ){ pcntl_wait($status); $child++; } } else { // we are the child echo "\t Starting new child | now we de have $child child processes\n"; // presumably doing something interesting sleep(rand(3,5)); exit; } } ?> ---- Server IP: 194.153.94.11 Probable Submitter: 130.82.103.133 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.pcntl-wait.php Edit -- http://master.php.net/note/edit/63594 Del: integrated -- http://master.php.net/note/delete/63594/integrated Del: useless -- http://master.php.net/note/delete/63594/useless Del: bad code -- http://master.php.net/note/delete/63594/bad+code Del: spam -- http://master.php.net/note/delete/63594/spam Del: non-english -- http://master.php.net/note/delete/63594/non-english Del: in docs -- http://master.php.net/note/delete/63594/in+docs Del: other reasons-- http://master.php.net/note/delete/63594 Reject -- http://master.php.net/note/reject/63594 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#106541) next »