【发布时间】:2019-08-20 18:56:30
【问题描述】:
对于我的 Laravel 应用程序,我使用 Goutte 包来抓取 DOM,这允许我使用 guzzle 设置。
$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
'timeout' => 15,
));
$goutteClient->setClient($guzzleClient);
$crawler = $goutteClient->request('GET', 'https://www.google.com/');
我目前正在使用 guzzle 的 timeout 功能,它会返回如下错误,例如当客户端超时时:
cURL 错误 28:操作在 1009 毫秒后超时,值为 0 接收到的字节数(参见http://curl.haxx.se/libcurl/c/libcurl-errors.html)
现在这很酷,但我实际上并不希望它返回 cURL 错误并停止我的程序。
我更喜欢这样的:
if (guzzle client timed out) {
do this
} else {
do that
}
我该怎么做?
【问题讨论】: