tobion/retry

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

dev-master / 0.1.x-dev 2015-06-05 15:52 UTC

README

PHP class for retrying code pieces in case of exceptions.

Build Status

Born out of a need of Tobias Schultze and Christian Riesen for a project at Liip which then found a specific merge request into Doctrine. We thought this works just as well on a generic basis.

Usage

Make sure it's autoloaded. Wrap the code you want retried with the class and execute it.

use Tobion\Retry\Retry;

// Anon function
$retry = new Retry(function () { return 42; });

// Outputs 42
echo $retry();

You can configure the exceptions to listen to for retries, the number of retries and the time between retries (in milliseconds) at construction time of the Retry class.

By default it will catch all exceptions

Development

To run tests, install composer, run composer install (or wherever you have composer installed) then run vendor/phpunit/phpunit/phpunit