https://github.com/eljam/circuit-breaker
PHP implementation of circuit breaker pattern
https://github.com/eljam/circuit-breaker
circuit-breaker microservice php
Last synced: about 2 months ago
JSON representation
PHP implementation of circuit breaker pattern
- Host: GitHub
- URL: https://github.com/eljam/circuit-breaker
- Owner: eljam
- License: mit
- Created: 2016-05-30T14:21:10.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-12-10T13:32:00.000Z (over 4 years ago)
- Last Synced: 2025-09-20T09:20:18.448Z (6 months ago)
- Topics: circuit-breaker, microservice, php
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 17
- Watchers: 4
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Circuit Breaker
===============
Circuit breaker is heavily used in microservice architecture to find issues between microservices calls.
The main idea is to protect your code from making unnecessary call if the microservice you call is down.
# Features
- Automatic update. (i.e you don't have to manually add success or failure method like other library)
- Return result from the protected function
- Retry timeout
- Exclude some exceptions from being throwned, return null instead.
- Multiprocess updates handled with a cache library. Supports all cache provider from (doctrine cache library).
- Event powered
[](https://travis-ci.org/eljam/circuit-breaker) [](https://scrutinizer-ci.com/g/eljam/circuit-breaker/?branch=master) [](https://coveralls.io/r/eljam/circuit-breaker) [](https://insight.sensiolabs.com/projects/dd1c1da1-d469-4113-80f3-874c9d1deffd) [](https://packagist.org/packages/eljam/circuit-breaker)
[](https://packagist.org/packages/eljam/circuit-breaker)
[](https://packagist.org/packages/eljam/circuit-breaker)
[](https://github.com/eljam/circuit-breaker/blob/master/LICENSE)
Full Example:
```php
true], $fileCache);
$breaker->addListener(CircuitEvents::SUCCESS, function (Event $event) {
$circuit = $event->getCircuit();
echo "Success:".$circuit->getFailures()."\n";
});
$breaker->addListener(CircuitEvents::FAILURE, function (Event $event) {
$circuit = $event->getCircuit();
echo "Increment failure:".$circuit->getFailures()."\n";
});
$breaker->addListener(CircuitEvents::OPEN, function (Event $event) {
$circuit = $event->getCircuit();
echo sprintf("circuit %s is open \n", $circuit->getName());
});
$breaker->addListener(CircuitEvents::CLOSED, function (Event $event) {
$circuit = $event->getCircuit();
echo sprintf("circuit %s is closed \n", $circuit->getName());
});
$breaker->addListener(CircuitEvents::HALF_OPEN, function (Event $event) {
$circuit = $event->getCircuit();
echo sprintf("circuit %s is half-open \n", $circuit->getName());
});
$result = $breaker->protect(function () {
throw new \Exception("An error as occured");
// return 'ok';
});
```