dev-master
9999999-devRetrying behavior for Guzzle
MIT
The Requires
The Development Requires
by Mike Evstropov
1.0.0
1.0.0.0Retrying behavior for Guzzle
MIT
The Requires
The Development Requires
by Mike Evstropov
Wallogit.com
2017 © Pedro Peláez
Retrying behavior for Guzzle
Retrying behavior for Guzzle, (*1)
Add dependency mikeevstropov/guzzle, (*2)
$ composer require mikeevstropov/guzzle
requests_limit, (*3)
Accepts:, (*4)
integer - positive integerDefault:, (*5)
1 - only one attemptMaximum number of attempts to receive a response., (*6)
repeat_on, (*7)
Accepts:, (*8)
array - array with a numeric indexDefault:, (*9)
array(0, 5) - repeat failed request or if response code is 5xxList of error codes for retrying requests:, (*10)
array(5) - on GuzzleHttp\Exception\ServerException (5xx code)array(4) - on GuzzleHttp\Exception\ClientException (4xx code)array(0) - other TransferException like GuzzleHttp\Exception\ConnectException
You can combine it like array(4, 5)., (*11)
<?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
Clone, (*12)
$ git clone https://github.com/mikeevstropov/guzzle.git
Go to project, (*13)
$ cd guzzle
Install dependencies, (*14)
$ composer install
Increase composer timeout. Since composer by default set it to 300 seconds., (*15)
$ composer config --global process-timeout 600
Run the tests, (*16)
$ composer test
Retrying behavior for Guzzle
MIT
Retrying behavior for Guzzle
MIT