Download the PHP package gabrielanhaia/php-circuit-breaker without Composer
On this page you can find all versions of the php package gabrielanhaia/php-circuit-breaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gabrielanhaia/php-circuit-breaker
More information about gabrielanhaia/php-circuit-breaker
Files in gabrielanhaia/php-circuit-breaker
Package php-circuit-breaker
Short Description Circuit breaker pattern for PHP with multiple storage adapters, event system, and manual override.
License MIT
Informations about the package php-circuit-breaker
PHP Circuit Breaker
A robust, production-ready implementation of the Circuit Breaker pattern for PHP. Protect your microservices from cascading failures with configurable thresholds, multiple storage backends, an event system, and manual override capabilities.
How It Works
| State | Description |
|---|---|
| Closed | Normal operation. Requests pass through. Failures are counted. |
| Open | Circuit is tripped. All requests are rejected immediately. |
| Half-Open | Recovery probe. Limited requests are allowed to test if the service has recovered. |
Installation
Optional Dependencies
Install only what you need:
Quick Start
Features
- Multiple storage backends — InMemory, Redis, APCu, Memcached, PSR-6, PSR-16
- Success threshold — require N consecutive successes before closing a half-open circuit
- Event system — react to state changes with listeners; optional PSR-14 bridge
- Manual override — force circuits open/closed for maintenance windows or testing
- State inspection — query effective circuit state at any time
- Immutable config — type-safe
CircuitBreakerConfigvalue object - Zero required extensions — only
ext-redis,ext-apcu,ext-memcachedneeded if you use those adapters - PHPStan level max — fully statically analyzed
- PHP 8.1+ — uses native enums, readonly properties, and named arguments
Documentation
| Topic | Description |
|---|---|
| Configuration | Config object, parameter table, exception mode |
| Storage Adapters | All 6 adapters, key scheme, comparison table |
| Event System | Events, sequence diagram, SimpleEventDispatcher, PSR-14 bridge |
| Manual Override | forceState(), clearOverride(), state inspection |
| Architecture | Class diagram, directory structure, request flow |
Upgrading from v2
See UPGRADE-3.0.md for a detailed migration guide.
Key Breaking Changes
| v2 | v3 |
|---|---|
CircuitStateEnum |
CircuitState (backing value 'close' → 'closed') |
CircuitBreakerAdapter (abstract class) |
CircuitBreakerStorageInterface |
new CircuitBreaker($adapter, $settings) |
new CircuitBreaker($storage, $config) |
Alert interface |
Event listeners |
AdapterException |
StorageException |
CircuitException |
OpenCircuitException |
ext-redis required |
ext-redis optional (suggested) |
Deprecated Methods (Removed in v4)
$cb->failed($service)→ use$cb->recordFailure($service)$cb->succeed($service)→ use$cb->recordSuccess($service)
Development
CI
GitHub Actions runs on PHP 8.1, 8.2, 8.3, 8.4 with three jobs:
- Tests — unit + integration (with Redis service)
- Static Analysis — PHPStan level max
- Code Style — PHP-CS-Fixer (PER-CS + PHP 8.1 migration)
Support
If this library helps you, consider buying me a coffee:
License
MIT — see LICENSE for details.
Created by Gabriel Anhaia | Buy Me a Coffee