21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
DEFINE(MAXPROCESS,25);
$arr = array('a','b','c','d','e','f','g','h','i','j','k');
$sub_arr = array_chunk($arr,3);
$sub_num = count($sub_arr);
for ($i=0;$i<$sub_num;$i++){
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} elseif ($pid) {
//echo "I'm the Parent $i\n";
$execute++;
if ($execute>=MAXPROCESS){
pcntl_wait($status);
$execute--;
}
} else {
echo "I am the child, $i pid = $pid \n";
echo "Bye Bye from $i\n";
print_r($sub_arr[$i]);
sleep(rand(5,7));
exit;
}
}
?>