GuzzleHttp 设置请求超时时间
admin 阅读:116 2024-03-01
GuzzleHttp 中使用 timeout 参数设置请求超时时间,避免在接口异常时大量占用 php 进程, timeout 参数的单位是秒。
use GuzzleHttpClient;
$url = "https://www.codesou.cn";
$client = new Client();
try {
$response = $client->post($url,['timeout' => 20]);
$data = json_decode($response->getBody()->getContents(),true);
return $data;
} catch (Exception $e) {
Log::error($e);
return rnull;
}声明
1、部分文章来源于网络,仅作为参考。 2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!



