Download the PHP package prestashop/circuit-breaker without Composer
On this page you can find all versions of the php package prestashop/circuit-breaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prestashop/circuit-breaker
More information about prestashop/circuit-breaker
Files in prestashop/circuit-breaker
Package circuit-breaker
Short Description A circuit breaker implementation for PHP
License MIT
Informations about the package circuit-breaker
Circuit Breaker, an implementation for resilient PHP applications
Main principles
This library is compatible with PHP 7.4+.
Installation
Use
Symfony Http Client and Guzzle Client implementations
By default, Circuit Breaker use the Symfony Http Client library, and all the client options are described in the official documentation.
For retro-compatibility, we let you use Guzzle Client instead of Symfony Http Client. To use Guzzle, you need to set the Guzzle client with setClient()
of the settings factory, like this example below:
Be aware, that the client options depend on the client implementation you choose!
For the Guzzle implementation, the Client options are described in the HttpGuzzle documentation.
Simple Circuit Breaker
You can use the factory to create a simple circuit breaker.
By default, you need to define 3 parameters for the circuit breaker:
- the failures: define how many times we try to access the service;
- the timeout: define how much time we wait before consider the service unreachable;
- the threshold: define how much time we wait before trying to access again the service (once it is considered unreachable);
The fallback callback will be used if the distant service is unreachable when the Circuit Breaker is Open (means "is used" if the service is unreachable).
You'd better return the same type of response expected from your distant call.
If you don't specify any fallback, by default the circuit breaker will return an empty string.
You can also define the client options (or even set your own client if you prefer).
Advanced Circuit Breaker
If you need more control on your circuit breaker, you should use the AdvancedCircuitBreaker
which manages more features:
- the stripped failures: define how many times we try to access the service when the circuit breaker is Half Open (when it retires to reach the service after it was unreachable);
- the stripped timeout: define how much time we wait before consider the service unreachable (again in Half open state);
- the storage: used to store the circuit breaker states and transitions. By default it's an
SimpleArray
so if you want to "cache" the fact that your service is unreachable you should use a persistent storage; - the transition dispatcher: used if you need to subscribe to transition events (ex: a dispatcher based on Symfony EventDispatcher is available)
Storage
Tests
Code quality
We also use PHPQA to check the Code quality during the CI management of the contributions.
If you want to use it (using Docker):
If you want to use it (using Composer):
All versions of circuit-breaker with dependencies
ergebnis/composer-normalize Version ^2.44
symfony/http-client Version ^5.4 || ^6