Simple circuit breaker class.
- Adjustable thresholds
- Adjustable cooldowns
- Events on change
- Any Doctine\Common\Cache\Cache implementation for persistence
Installation is via composer, in the usual manner:
$ composer require solution10/circuitbreaker
<?php
$persistence = new \Doctrine\Common\Cache\ArrayCache();
$breaker = new \Solution10\CircuitBreaker\CircuitBreaker('my_backend_service', $persistence);
if ($breaker->isClosed()) {
$response = doSomething();
if ($response) {
$breaker->success();
} else {
$breaker->failure();
}
} else {
gracefullyDegrade();
}
(or the /docs folder in the repo)
- PHP >= 5.5