pcntl_fork problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

 I'm trying to use pcntl_fork to speedup some checks I do on remote
servers. The problem is the 2nd child is created only when the 1st has
finished the execution of the whole inner for block.

here's the code:

$childs=0;    //contatore childs
for ($childs=0; $childs<MAX_THREADS;$childs++) {  //MAX_THREADS is the
                                                  //number of forks to
be done
    if ($pid == -1) {
         die('could not fork');
    } else if ($pid) {
        print "Child $childs has pid $pid\n";
    } else {
        print "in child $childs\n";
        for ($z=0;$z<$limit;$z++) {
if ($pid) {
    while ($childs>0) {
        print "Child $cid exited with status $status\n";
    print "parent terminated\n";

How can I have all the child processes run at the same time without
waiting for the previous child to exit ?



Site Timeline