php popen实现多任务
程序员文章站
2022-05-10 16:09:36
...
Php代码
$update_num = 1000;
$limit = 100;
$p_num = 0;
$line_cmd = 'ps -ef | grep doit.php | grep -v grep | wc -l';
$exec_cmd = '/usr/local/php/bin/php doit.php %s & > /dev/null 2>&1';
$t1 = microtime(1);
for($i = 0 ; $i if($p_num $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 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);
?>
摘自 网络营销
$update_num = 1000;
$limit = 100;
$p_num = 0;
$line_cmd = 'ps -ef | grep doit.php | grep -v grep | wc -l';
$exec_cmd = '/usr/local/php/bin/php doit.php %s & > /dev/null 2>&1';
$t1 = microtime(1);
for($i = 0 ; $i if($p_num $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 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);
?>
Php代码
sleep(2);
$fp = fopen('doit.txt','a');
fwrite($fp,$argv[1]."\n");
fclose($fp);
exit(0);
?> (fblww-0227)
摘自 网络营销
上一篇: 微信自定义菜单的处理开发示例_PHP教程
下一篇: Oracle注入简单命令整理