where in I need to fork a process. Then when their task completes, the parent process should go ahead and do some other work. How can this be done? Here's what I have done
$sql = "call some_sample_proc()";
$res = $dbConn->query($sql);
$i=0;
$memcacheData = array();
while($row = $dbConn->fetch_assoc()) {
$value = $row['col1'].$row['col2'].$row['col3'];
$memcachceData[$i++] = $value;
}
for($i=0; $i<5; $i++) {
$pid = pcntl_fork();
if($pid == 0) {
$im = $i;
echo "forked process $i \n"; // -- 1
exit;
} else if($pid == -1) {
echo "Could not fork \n";
}
}
while (pcntl_waitpid(0, $status) != -1) {
$status = pcntl_wexitstatus($status);
echo "Child $status completed $im\n ";
$childCompleteCount ++;
}
echo "completion count $childCompleteCount\n";
if($childCompleteCount == 5) {
echo "All finished\n";
//exit; //if this is uncommented, ONLY THEN the program finishes
}
When I execute the program with this snippet of code I get this output...
forked process 0
forked process 1
forked process 3
forked process 2
forked process 4
Child 0 completed 0
Child 0 completed 0
Child 0 completed 0
Child 0 completed 0
Child 0 completed 0
completion count 5
All finished
But after printing completion count 5 program seems to hang. It doesnt return to prompt. So now that we understand that all children (forked) processes have finished, how do we resume the further execution?