由於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) ); 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); } }