$update_num = 1000;
$limit = 100;
$p_num = 0;
$line_cmd = 'ps -ef grep doit.php grep -v grep wc -l';
http://www.gaodaima.com/?p=50127php popen:php popen实现多任务_php
$exec_cmd = '/usr/local/php/bin/php doit.php %s & > /dev/null 2>&1';
$t1 = microtime(1);
for($i = 0 ; $i < $update_num ; $i++){
if($p_num <=0){
$fp1 = popen($line_cmd,'r');
//current shell process numbers
$line = fread($fp1,512);
pclose($fp1);
//processes can be pushed
$p_num = $limit - $line;
if($p_num <= 0 ){
usleep(100);
}
}
$p_num = $p_num -1;
$cmd = sprintf($exec_cmd,$i);
$fp = popen($cmd,'r');
pclose($fp);
}
$t2 = microtime(1);
echo round($t2 - $t1,2);
?>
sleep(2);
$fp = fopen('doit.txt','a');
fwrite($fp,$argv[1]."/n");
fclose($fp);
exit(0);
?> 本文链接http://www.cxybl.com/html/wlbc/Php/20120531/27133.html
欢迎大家阅读《php popen:php popen实现多任务_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~