Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: How to check for timeout exception in Guzzle 4?

Tags:

Guzzle throws an exception if an error occured during the request. Unfortunately, there does not seem to be an error specific to timeouts - which is important for me as I know that those can ocassionally occur. I'd like to retry the corresponding request and need to able to tell if the error occured due to a timeout.

From the docs:

// Timeout if a server does not return a response in 3.14 seconds.
$client->get('/delay/5', ['timeout' => 3.14]);
// PHP Fatal error:  Uncaught exception 'GuzzleHttp\Exception\RequestException'

The RequestException has the info in itsmessage property:

"cURL error 28: Operation timed out after 3114 milliseconds with 0 bytes received"

So I could evaluate the message pattern but this feels kinda wrong, because those messages could easily be changed in the future.

Is there a better/more stable way to check for timeouts when using guzzle 4?