本文整理匯總了PHP中GuzzleHttp\ClientInterface::getAsync方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClientInterface::getAsync方法的具體用法?PHP ClientInterface::getAsync怎麽用?PHP ClientInterface::getAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GuzzleHttp\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::getAsync方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getAsync
/**
* GET action
*
* @param string $url the target URL
* @param array $options
* @return PromiseInterface the body of the result
*/
public function getAsync($url, array $options = [])
{
return $this->client->getAsync($url, $options)->then(function (ResponseInterface $response) {
if ($response->getStatusCode() !== 200) {
throw new HttpException('HTTP error ' . $response->getStatusCode(), $response->getStatusCode());
}
return $response->getBody()->getContents();
}, function (RequestException $e) {
throw new HttpException($e->getMessage());
});
}
示例2: yieldAsyncPromisesForImageUrls
protected function yieldAsyncPromisesForImageUrls() : \Generator
{
foreach ($this->imageUrls as $url) {
(yield $url => $this->guzzleClient->getAsync($url));
}
}