由于PHP的进程是不支持多线程的,有些场景为了方便以及提高性能,可以用PHP实现多进程以弥补这个不足:
代码如下:
#!/usr/bin/env PHP
PHP
$cmds=array(
array('/apps/bin/launcher.PHP','charge/promotion_props_stat.PHP','mobile',1),
array('/apps/bin/launcher.PHP',2),'click',2)
);
PHP
$cmds=array(
array('/apps/bin/launcher.PHP','charge/promotion_props_stat.PHP','mobile',1),
array('/apps/bin/launcher.PHP',2),'click',2)
);
foreach($cmds as $cmd){
$pid=pcntl_fork();
if($pid==-1){ //进程创建失败
die('fork child process failure!');
}
else if($pid){ //父进程处理逻辑
pcntl_wait($status,WNOHANG);
}
else{ //子进程处理逻辑
pcntl_exec('/usr/local/bin/PHP',$cmd);
}
}