9951 explained code solutions for 126 technologies


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

Edit this code on GitHub