aguimaraes / circuit-breaker
Implementation of the circuit breaker pattern
Installs: 55 805
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 4
Forks: 2
Open Issues: 1
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^6
- predis/predis: ^1.1
Suggests
- ext-acpu: In order to use the APCu adapter
- predis/predis: In order to use the Redis adapter
README
Usage example
$cb = new Aguimaraes\CircuitBreaker( new Aguimaraes\Adapter\ACPu() ); // number of errors necessary to open the circuit $cb->setThreshold('my-service', 10); // wait x seconds to check if service is back $cb->setTimeout('my-service', 60); $response = null; if ($cb->isAvailable('my-service')) { try { $response = $service->makeCall(); $cb->reportSuccess('my-service'); } catch (ServiceException $e) { $cb->reportFailure('my-service'); } catch (NonServiceRelatedException $e) { // something went wrong and it was not the service fault } }