Download the PHP package stfn/php-circuit-breaker without Composer
On this page you can find all versions of the php package stfn/php-circuit-breaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stfn/php-circuit-breaker
More information about stfn/php-circuit-breaker
Files in stfn/php-circuit-breaker
Package php-circuit-breaker
Short Description This is circuit-breaker pattern implemented in PHP
License MIT
Homepage https://github.com/stfndamjanovic/circuit-breaker
Informations about the package php-circuit-breaker
Circuit breaker in PHP
This package provides an implementation of the circuit breaker pattern in PHP. You can find more info about it here.
Installation
You can install the package via composer:
Usage
Wrap your potentially error-prone function with the circuit breaker, and it will monitor and handle failures.
States
Circuit breaker can have 4 different states.
Closed
In the Closed
state, the circuit breaker is fully operational, allowing calls to the 3rd party service. Any exceptions that occur during this state are counted.
Half Open
The Half Open state is a transitional phase where the circuit breaker allows a limited number of calls to the 3rd party service. If these calls are successful, the circuit is closed again. However, if the service continues to exhibit issues, the circuit is moved back to the Open
state.
Open
The Open
state indicates that the circuit breaker has detected a critical failure, and the call method will fail immediately, throwing a CircuitOpenException
exception.
Force Open
Force Open
is not part of the regular flow. It can be utilized when intentional suspension of calls to a service is required. In this state, a CircuitOpenException
will be thrown.
To force the circuit breaker into the Force Open state, use the following:
This feature provides a manual override to stop calls to a service temporarily, offering additional control when needed.
Storage
By default, the circuit breaker uses InMemoryStorage
as a storage driver, which is not suitable for most of PHP applications.
More useful would be to use RedisStorage
.
You could also write your implementation of storage. You should just implement CircuitBreakerStorage
interface.
Configuration
Each circuit breaker has default configuration settings, but you can customize them to fit your needs:
Excluding some failures
Change the circuit breaker behavior by configuring it to exclude certain types of failures:
Listeners
You can add listeners for circuit breaker actions by extending the CircuitBreakerListener class:
Attach the listener to the circuit breaker:
Testing
License
The MIT License (MIT). Please see License File for more information.
All versions of php-circuit-breaker with dependencies
ext-redis Version *