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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-01-04
  • 2021-12-26
  • 2021-11-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-06-11
  • 2021-09-13
  • 2022-12-23
相关资源
相似解决方案