mikeevstropov / guzzle
Retrying behavior for Guzzle
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/mikeevstropov/guzzle
Requires
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^5.7
- webmozart/assert: ^1.2
This package is not auto-updated.
Last update: 2021-06-26 12:04:09 UTC
README
Retrying behavior for Guzzle
Installation
Add dependency mikeevstropov/guzzle
$ composer require mikeevstropov/guzzle
New options
- 
requests_limit Accepts: - integer- positive integer
 Default: - 1- only one attempt
 Maximum number of attempts to receive a response. 
- 
repeat_on Accepts: - array- array with a numeric index
 Default: - array(0, 5)- repeat failed request or if response code is 5xx
 List of error codes for retrying requests: - array(5)- on- GuzzleHttp\Exception\ServerException(5xx code)
- array(4)- on- GuzzleHttp\Exception\ClientException(4xx code)
- array(0)- other- TransferExceptionlike- GuzzleHttp\Exception\ConnectException
 You can combine it like array(4, 5).
Usage
<?php $client = new \GuzzleHttp\Client(); // Let's try to request "http://httpstat.us/503" that // page will always return "503 Service Unavailable" $response = $client->get('http://httpstat.us/503', [ 'requests_limit' => 3, ]); // will thrown GuzzleHttp\Exception\ServerException after 3 attempts // We can pass option "repeat_on" to prevent retrying // if response has code 5xx (by default [0, 5]) $response = $client->get('http://httpstat.us/503', [ 'requests_limit' => 3, 'repeat_on' => array(0, 4) ]); // will thrown GuzzleHttp\Exception\ServerException after first request // But same options with request to the page that return 4xx // will have 3 attempts, because we pass "4" as array item in // option "repeat_on" $response = $client->get('http://httpstat.us/402', [ 'requests_limit' => 3, 'repeat_on' => array(0, 4) ]); // will thrown GuzzleHttp\Exception\ServerException after 3 attempts
Development
Clone
$ git clone https://github.com/mikeevstropov/guzzle.git
Go to project
$ cd guzzle
Install dependencies
$ composer install
Increase composer timeout. Since composer by default set it to 300 seconds.
$ composer config --global process-timeout 600
Run the tests
$ composer test