GuzzleHttp 并发请求应该怎么写?
use GuzzleHttp\Client;
use GuzzleHttp\Promise;
$client = new Client(['base_uri' => API_URL]);
$promises = [];
$promises[] = $client->getAsync('/path');
$promises[] = $client->getAsync('/path');
$promises[] = $client->getAsync('/path');
$promises[] = $client->getAsync('/path');
$responses = Promise\Utils::unwrap($promises);
foreach ($responses as $key => $response) {
// todo
}
想请问一下,我使用 GuzzleHttp 这样写的请求是顺序执行的,不是并发请求。
应该怎么写才是并发请求?
推荐文章: