transient-error-handling
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
Provide a way to easily retry actions on transient errors / exceptions such as a network failure., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require borisguery/transient-error-handling, (*4)
## Usage
``` php
use Bgy\TransientFaultHandling\RetryStrategies\FixedInterval;
use Bgy\TransientFaultHandling\RetryPolicy;
use Bgy\TransientFaultHandling\ErrorDetectionStrategies\TransientErrorCatchAllStrategy;
$retryCount = 10;
$retryIntervalInMicroseconds = 1000000 // 1 sec
$retryStrategy = new FixedInterval($retryCount, $retryIntervalInMicroseconds);
$errorDetectionStrategy = new TransientErrorCatchAllStrategy(); // You may want to implement your own
$retryPolicy = new RetryPolicy($errorDetectionStrategy, $retryStrategy);
$retryPolicy->execute(function() {
// try to connect to MySQL
throw new ConnectionError("Unable to connect to MySQL");
});
// This configuration will try to execute 10 times the function everyseconds if an exception is thrown.
Change log
Please see CHANGELOG for more information on what has changed recently., (*5)
Testing
bash
$ composer test, (*6)
Credits
License
The MIT License (MIT). Please see License File for more information., (*7)