请教一下guzzle的pool问题
use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
$stack = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(Middleware::mapRequest(function (RequestInterface $request) {
Log::write(':请求的数据:' . $request->getBody());
return $request;
}));
$client = new Client(['handler' => $stack]);
$requests = function ($total) {
$uri = 'https://www.google.com';
for ($i = 0; $i < $total; $i++) {
yield new Request('GET', $uri);
}
};
$pool = new Pool($client, $requests(100), [
'concurrency' => 5,
'fulfilled' => function ($response, $index) {
// this is delivered each successful response
},
'rejected' => function ($reason, $index) {
// this is delivered each failed request
},
]);
// Initiate the transfers and create a promise
$promise = $pool->promise();
// Force the pool of requests to complete.
$promise->wait();
发现一个问题,这个pool并发如果前面的一个阻塞了还没有收到响应,后面的请求并不会被请求出去,我用中间件记录了请求的body来看,前面的请求没执行完后面的不会执行,原本就是这么设计的吗?
推荐文章: