https://github.com/compwright/should-retry
https://github.com/compwright/should-retry
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/compwright/should-retry
- Owner: compwright
- License: mit
- Created: 2025-03-14T16:42:34.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-14T16:47:12.000Z (about 1 year ago)
- Last Synced: 2025-09-30T19:52:23.032Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# compwright/should-retry
## Installation
$ composer require compwright/should-retry
## Usage with Guzzle HTTP library
The popular Guzzle HTTP library includes a retry middleware:
```php
use Compwright\ShouldRetry\ShouldRetry;
use Compwright\ShouldRetry\RetryAfter;
$handler = GuzzleHttp\HandlerStack::create();
$handler->push(
GuzzleHttp\Middleware::retry(
new ShouldRetry(),
new RetryAfter()
),
'retry'
);
$client = new GuzzleHttp\Client([
'handler' => $handler,
]);
```
## Configuration
Both ShouldRetry and RetryAfter are configurable via setters:
```php
$shouldRetry = (new ShouldRetry())
->setMaxRetries(5)
->setRetryOnStatusCodes(429)
->setLogger($logger); // attach PSR-3 debug logger
$retryAfter = (new RetryAfter())
->setRetryAfterHeader('x-rate-limit-reset')
->setFallbackStrategy($fallback);
```
Default configuration:
* Retry up to 3 times
* Retry on 429, 500, 502, 503, 504 error codes
* When retrying, wait `Retry-After` seconds
* If header is missing, use exponential backoff
## License
MIT License