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 use PHP Guzzle to make a batch request?
- How to troubleshoot cURL error 60 with Guzzle in PHP?
- How to send multipart requests with Guzzle in PHP?
- How to set a user agent in PHP Guzzle?
- How to convert a response to an array with PHP Guzzle?
- How to use cookies with Guzzle in PHP?
- How to make HTTP request with PHP Guzzle?
- How to update PHP Guzzle?
- How to stream with PHP Guzzle?
- How to add a bearer token in PHP Guzzle?
See more codes...