美文网首页
Swoole多个子进程运行测试

Swoole多个子进程运行测试

作者: HueyYao | 来源:发表于2020-12-21 23:00 被阅读0次

Swoole多个子进程运行测试

<?php

echo "processStart:".date('Y-m-d H:i:s').PHP_EOL;
$workers = [];
$urls = [
    'https://a.com',
    'https://b.com',
    'https://b.com',
];
for ($n = 0; $n < 3; $n++) {
    //开启子进程
    $process = new swoole_process(function($worker) use ($n,$urls) {
        //curl
        $content  = curlData($urls[$n]);
        echo $content.PHP_EOL;
        //$worker->write($content.PHP_EOL);//写入管道中
    },true);
    $pid = $process->start();
    $workers[$pid] = $process;
}
//获取管道内容
foreach ($workers as $process) {
    echo $process->read();
}
//模拟耗时1秒
function curlData($url){
    sleep(1);
    return $url."Success:".PHP_EOL;
}
echo "processEnd:".date('Y-m-d H:i:s').PHP_EOL;

相关文章

网友评论

      本文标题:Swoole多个子进程运行测试

      本文链接:https://www.haomeiwen.com/subject/ogxjnktx.html