echo "process-start-time:".date('Y-m-d H:i:s').PHP_EOL;
$workers = [];
$curls = [
'http://baidu.com',
'http://sina.com.cn',
'http://qq.com',
'https://www.baidu.com/s?wd=imooc',
'https://www.baidu.com/s?wd=wnaglei',
'https://www.baidu.com/s?wd=wangmin',
];
for ($i=0; $i<6; $i++) {
$process = new swoole_process(function (swoole_process $worder) use($i, $curls) {
$content = curlData($curls[$i]);
// echo $content.PHP_EOL;
$worder->write($content.PHP_EOL);
}, true);
$pid = $process->start();
$workers[$pid] = $process;
}
foreach ($workers as $process) {
echo $process->rend();
}
function curlData($curl) {
sleep(1);
return $curl.'success'.PHP_EOL;
}
echo "process-end-time:".date('Y-m-d H:i:s').PHP_EOL;
报错:
process-start-time:2019-01-19 04:37:38
PHP Fatal error: Uncaught Error: Call to undefined method Swoole\Process::rend() in /Users/alanwang/wwwroot/demo/process/curl.php:31
Stack trace: