php-guzzleHow to set a timeout for a request with PHP Guzzle?
You can set a timeout for a request with PHP Guzzle by using the timeout
option in the request options array.
Example code
$client = new GuzzleHttp\Client();
$response = $client->request('GET', 'http://www.example.com', [
'timeout' => 2.0,
]);
Output example
GuzzleHttp\Psr7\Response
Code explanation
$client = new GuzzleHttp\Client();
- creates a new Guzzle client instance$client->request('GET', 'http://www.example.com', [
- sends a GET request to the specified URL'timeout' => 2.0,
- sets the timeout for the request to 2 seconds]);
- closes the request options array
Helpful links
More of Php Guzzle
- How to use PHP Guzzle to make a batch request?
- How to set a user agent in PHP Guzzle?
- How to post form data with PHP Guzzle?
- How to make an asynchronous send with PHP Guzzle?
- How to get the response body in PHP Guzzle?
- How to convert a response to an array with PHP Guzzle?
- How to send multipart requests with Guzzle in PHP?
- How to use cookies with Guzzle in PHP?
- How to make HTTP request with PHP Guzzle?
- How to handle a RequestException with PHP Guzzle?
See more codes...