解析PHP实现多进程并行执行脚本
由于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','charge/promotion_props_stat.php','mobile',2), array('/apps/bin/launcher.php','charge/promotion_props_stat.php','click',1), array('/apps/bin/launcher.php','charge/promotion_props_stat.php','click',2), array('/apps/bin/launcher.php','charge/promotion_props_stat.php',1), array('/apps/bin/launcher.php','charge/promotion_props_stat.php',2) ); <p>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); } } </p>
相关推荐
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28
wwwsurfphpseocom 2020-10-28
diskingchuan 2020-10-23
savorTheFlavor 2020-10-23