并发批量请求

优质
小牛编辑
129浏览
2023-12-01

一种写法同时支持 Curl 和 Swoole

use \Yurun\Util\YurunHttp\Co\Batch;
use \Yurun\Util\HttpRequest;

$result = Batch::run([
    (new HttpRequest)->url('https://www.imiphp.com'),
    (new HttpRequest)->url('https://www.yurunsoft.com'),
]);

var_dump($result[0]->getHeaders(), strlen($result[0]->body()), $result[0]->getStatusCode());

var_dump($result[1]->getHeaders(), strlen($result[1]->body()), $result[1]->getStatusCode());