php支持多线程吗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)
);
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);
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。