Azoruk
2 months ago
1143
1
Feedback

Catch cURL error with Laravel?

Posted 2 months ago by Azoruk

For my Laravel application, I use the Goutte package to crawl DOMs, which allows me to use guzzle settings.

$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
    'timeout' => 15,
));
$goutteClient->setClient($guzzleClient);
$crawler = $goutteClient->request('GET', 'https://www.google.com/');

I'm currently using guzzle's timeout feature, which will return an error like this, for example, when the client times out:

cURL error 28: Operation timed out after 1009 milliseconds with 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)

Now this is cool and all, but I don't actually want it to return a cURL error and stop my program.

I'd prefer something like this:

if (guzzle client timed out) {
    do this
} else {
    do that
}

How can I do this?

Please sign in or create an account to participate in this conversation.