Hi,
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_THR EADS;$childs++) { //MAX_THREADS is the
maximum
//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++) {
myVeryLongFunct ion();
};
exit($childs);
};
};
if ($pid) {
while ($childs>0) {
$cid=pcntl_wait pid(-1,&$status);
print "Child $cid exited with status $status\n";
$childs--;
};
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 ?
TIA
giuliano
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_THR EADS;$childs++) { //MAX_THREADS is the
maximum
//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++) {
myVeryLongFunct ion();
};
exit($childs);
};
};
if ($pid) {
while ($childs>0) {
$cid=pcntl_wait pid(-1,&$status);
print "Child $cid exited with status $status\n";
$childs--;
};
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 ?
TIA
giuliano