php-guzzleHow to set a timeout for a Guzzle client in PHP?
Setting a timeout for a Guzzle client in PHP is easy. You can set a timeout for a Guzzle client by passing a timeout
option to the GuzzleHttp\Client
constructor.
$client = new GuzzleHttp\Client([
'timeout' => 10.0,
]);
The above code will set the timeout to 10 seconds.
Code explanation
GuzzleHttp\Client
: This is the Guzzle client class.timeout
: This is the option used to set the timeout.10.0
: This is the value of the timeout in seconds.
Helpful links
More of Php Guzzle
- How to set a user agent in PHP Guzzle?
- How to set a timeout for a request with PHP Guzzle?
- How to add an SSL certificate to a request with PHP Guzzle?
- How to handle a RequestException with PHP Guzzle?
- How to make an asynchronous send with PHP Guzzle?
- How to convert a response to an array with PHP Guzzle?
- What version of PHP is required for Guzzle?
- How to make HTTP request with PHP Guzzle?
- How to stream with PHP Guzzle?
- How to troubleshoot cURL error 60 with Guzzle in PHP?
See more codes...