eljam / circuit-breaker Goto Github PK
View Code? Open in Web Editor NEWPHP implementation of circuit breaker pattern
License: MIT License
PHP implementation of circuit breaker pattern
License: MIT License
Documentation is currently providing a single example, that doesn't explain so much.
The example mentions a GitHub API, but then no reference to any call is shown in the code (not even in an abstract way, e.g. via code comments).
Please add a stable version tag!
So we can require this correctly in composer
tl;dr: add a list of "allowed exceptions" that will be thrown without opening the circuit.
I'm using this lib to, among other things, protect the interaction with my SMS service.
This service eventually throws some validation exceptions like InvalidCountryException
when the phone I try to text is not within the list of supported/allowed countries.
I'd like to catch this exception without opening the circuit since the service itself didn't actually fail.
Do you think this would make sense? If so I can arrange the PR so you don't have to bother with it.
BTW, do you have some way I could donate you a coffee?
Thanks for the lib!
Any chance you'd be willing to make this PHP 5.4-compatible?
I'm currently using ejsmont-artur/php-circuit-breaker
but your solution seems more elegant and I'd like to give it a try.
(I know 5.4 is dead, but Red Hat insists on using it and in my company they don't allow installing anything that is not Red Hat-approved -- they won't even use Red Hat Software Collections, go figure...)
The current implementation of Breaker class requires to inject \Symfony\Component\Cache\Adapter\AbstractAdapter
.
I think it should type hint for more generic \Symfony\Component\Cache\Adapter\AdapterInterface
, since the concrete object makes harder to use dependency injection (for example, with Symfony).
I can provide a PR.
It would be nice to have a Breaker Box / Panel where you can retrieve all declared Breakers and be able to fetch their status. I'm currently working on an UX that would allow people to close/open Breaker manually, and solely relying on events is not possible. Would go like this:
$breaker = new Breaker("some_breaker");
$breakerBox = new BreakerBox();
$breakerBox->add($breaker);
foreach ($breakerBox->getBreakers() as $name) {
$breakerBox->isOpen($name); // let's say it is false
$breakerBox->close($name); // use its own writeToStore function to update the Breaker's Circuit
$breakerBox->isOpen($name); // now it would be true
By cleverly using bind(..., Breaker::class), BreakerBox would be able to access Handler and Circuit of a Breaker without changing its interface contract.
I know it's kinda replicating the Feature Flag here, and before working on a PR, I'm pinging to know if it's the intended direction for this repo.
Btw your quite high on libraries.io for php circuit breakers, good job pal !
Events should be dispatched using the object as the first argument (and maybe the name as the second argument, for legacy compatibility).
The current implementation of dispatching names as the first argument is incompatible with modern libraries/frameworks.
I can provide a PR.
You should make coveralls a composer dev-dependency, because it is only used when testing your code.
I've noticed Doctrine's Cache::contains()
is always returning true
when using MemcacheCache
.
// on Breaker.php
protected function loadCircuit($name)
{
if ($this->store->contains($name)) {
$circuit = $this->store->fetch($name); // always true when using MemcacheCache
} else {
$circuit = new Circuit($name);
}
// ...
Would it be a problem if we just checked for a false
response on fetch()
or are there known issues with other cache drivers?
It seems this would not be a problem:
@return mixed The cached data or FALSE, if no cache entry exists for the given id.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.