Download the PHP package omidrezasalari/circuit-breaker-bundle without Composer
On this page you can find all versions of the php package omidrezasalari/circuit-breaker-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download omidrezasalari/circuit-breaker-bundle
More information about omidrezasalari/circuit-breaker-bundle
Files in omidrezasalari/circuit-breaker-bundle
Package circuit-breaker-bundle
Short Description A Symfony bundle implementing the Circuit Breaker pattern.
License
Informations about the package circuit-breaker-bundle
Circuit Breaker Bundle
This package is a Symfony bundle that implements the Circuit Breaker pattern. It helps protect your services from repeated requests when failures occur. The package is designed to allow you to easily change the storage mechanism (e.g., Redis, APCu, or custom implementations).
Features
- Circuit Breaker Pattern: Prevents repeated requests after multiple failures.
- Flexible Storage: By default, it uses APCu, but you can switch to Redis or any custom storage implementation.
- Configurable: Dynamically configure failure thresholds and timeout periods via Symfony configuration files.
- Symfony 6+ Compatible: Integrates seamlessly with modern Symfony projects.
Installation
1. APCu Implementation (Optimized and Persistent in Memory)
APCu is an internal PHP cache that stores data in shared memory and can be accessed across different requests on a server.
1.1 Install and Enable APCu
Before using APCu as a storage mechanism for the Circuit Breaker bundle, ensure that APCu is installed and enabled on your server.
1.2 Check if APCu is installed:
`
If it's not installed, you can install it with the following commands:
- For Linux (Ubuntu/Debian): `
- For macOS: `
1.3 Enable APCu for CLI (Command Line Interface):
Edit your php.ini
file to enable APCu for the CLI:
`
2. Install the package via Composer, run the following command:
`
After installing, register the bundle in your config/bundles.php
:
Configuration
The circuit breaker bundle uses a configurable failure threshold and timeout period. You can configure these parameters in your config/services.yaml
.
Package Configuration File (circuit_breaker.yaml):
This file is placed under the directory and allows users to define custom configurations for the package. The file looks like this
Configuration Details:
Storage Service:
By default, the storage_service is set to . If you prefer to use , simply change this value in : `
and parameters:
These values control how many failures are allowed before the circuit breaker trips and for how long it stays open.
Custom Storage
The bundle comes with a default ApcuStorage
implementation. If you want to use a different storage solution, implement the StorageInterface
and pass it to the CircuitBreaker
service.
Usage
Here’s an example of how to use the CircuitBreaker service:
API
isOpen(string $serviceName): bool
Checks whether the circuit breaker for the given service is open. Returns true
if open, false
if not.
attemptSuccess(string $serviceName): void
Called when a service operation is successful. Resets the failure count and closes the circuit breaker.
attemptFailure(string $serviceName): void
Called when a service operation fails. Increments the failure count. If the failure threshold is reached, the circuit breaker will open.
Running Tests
To run the tests for the bundle, you can use PHPUnit:
Contributing
If you'd like to contribute to the development of this bundle, feel free to fork the repository, create a branch, and submit a pull request. Please ensure your code follows the coding standards and includes tests for any new features or bug fixes.
License
This bundle is open-source and available under the MIT License.
All versions of circuit-breaker-bundle with dependencies
symfony/framework-bundle Version ^6.0 || ^7.0
predis/predis Version *
ext-apcu Version *