【发布时间】:2023-03-27 14:25:01
【问题描述】:
我正在使用 guzzle 承诺发送并发请求,但我想控制并发性,这就是我想使用 guzzle 池的原因。我如何将 guzzle promise 转换为 guzzle pool。这是我的代码:
public function getDispenceryforAllPage($dispencery)
{
$GetAllproducts = [];
$promiseGetPagination = $this->client->getAsync($dispencery)
->then(function ($response) {
return $this->getPaginationNumber($response->getBody()->getContents());
});
$Pagination = $promiseGetPagination->wait();
$pagearray = array();
for($i=1;$i<=$Pagination; $i++){
$pagearray[] = $i;
}
foreach($pagearray as $page_no) {
$GetAllproducts[] = $this->client->getAsync($dispencery.'?page='.$page_no)
->then(function ($response) {
$promise = $this->getData($response->getBody()->getContents());
return $promise;
});
}
$results = GuzzleHttp\Promise\settle($GetAllproducts)->wait();
return $results;
}
【问题讨论】:
标签: php httprequest guzzle guzzle6