无为清净楼资源网 Design By www.qnjia.com

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

标签:
php,多进程

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com