Download the PHP package philiprehberger/php-retry without Composer
On this page you can find all versions of the php package philiprehberger/php-retry. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download philiprehberger/php-retry
More information about philiprehberger/php-retry
Files in philiprehberger/php-retry
Download philiprehberger/php-retry
More information about philiprehberger/php-retry
Files in philiprehberger/php-retry
Vendor philiprehberger
Package php-retry
Short Description Composable retry utility with exponential backoff, jitter, and exception filtering
License MIT
Homepage https://github.com/philiprehberger/php-retry
Package php-retry
Short Description Composable retry utility with exponential backoff, jitter, and exception filtering
License MIT
Homepage https://github.com/philiprehberger/php-retry
Please rate this library. Is it a good library?
Informations about the package php-retry
PHP Retry
Composable retry utility with exponential backoff, jitter, and exception filtering.
Requirements
- PHP 8.2+
Installation
Usage
Basic retry
Exponential backoff with jitter
Linear backoff
Constant delay
Exception filtering
Only retry on specific exceptions:
Exclude specific exceptions from retrying:
Conditional Retry
Use shouldRetry() to provide a predicate that receives the exception and attempt number:
Use retryOnlyOn() to retry only for specific exception types:
Retrieve the total number of attempts after execution with getAttempts():
Time budget
Stop retrying after a total time budget is exceeded:
Retry forever (with safety)
Callbacks
Success callback
Checking retry status
API
| Method | Description |
|---|---|
Retry::times(int $maxAttempts) |
Create a retry builder with a maximum number of attempts |
Retry::forever() |
Create a retry builder that retries indefinitely |
->backoff(bool $exponential = true, int $baseMs = 100, int $maxMs = 10000) |
Configure exponential (or constant when $exponential = false) backoff |
->onTimeout(callable $callback) |
Callback invoked with the last exception (or null) when maxDuration is exceeded |
->linear(int $delayMs) |
Configure linear backoff |
->constant(int $delayMs) |
Configure constant delay |
->jitter(bool $enabled) |
Enable or disable jitter |
->onlyIf(callable $predicate) |
Only retry when predicate returns true |
->except(string ...$exceptionClasses) |
Exclude specific exception types from retrying |
->shouldRetry(callable $predicate) |
Predicate receiving exception and attempt number; return false to stop |
->retryOnlyOn(string ...$exceptionClasses) |
Only retry for the given exception types (sugar for shouldRetry) |
->getAttempts() |
Get the total number of attempts made after execution |
->maxDuration(int $ms) |
Set maximum total duration for all attempts |
->beforeRetry(callable $callback) |
Callback invoked before each retry |
->afterRetry(callable $callback) |
Callback invoked after each attempt |
->onSuccess(callable $callback) |
Callback invoked with RetryResult after successful execution |
->run(callable $operation) |
Execute the operation with retry logic |
$result->wasRetried() |
Returns true if more than one attempt was made |
$result->totalDuration() |
Total elapsed time across all attempts in milliseconds |
Development
Support
If you find this project useful:
License
MIT
All versions of php-retry with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
The package philiprehberger/php-retry contains the following files
Loading the files please wait ...