Download the PHP package gabrielanhaia/laravel-circuit-breaker without Composer
On this page you can find all versions of the php package gabrielanhaia/laravel-circuit-breaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gabrielanhaia/laravel-circuit-breaker
More information about gabrielanhaia/laravel-circuit-breaker
Files in gabrielanhaia/laravel-circuit-breaker
Package laravel-circuit-breaker
Short Description Laravel integration for PHP Circuit Breaker — multiple storage drivers, middleware, Artisan commands, and event system
License MIT
Homepage https://github.com/gabrielanhaia/laravel-circuit-breaker
Informations about the package laravel-circuit-breaker
Laravel Circuit Breaker
A Laravel integration for PHP Circuit Breaker v3 with multiple storage drivers, HTTP middleware, Artisan commands, and full event system integration.
What Is a Circuit Breaker?
When your application calls an external service (payment gateway, email API, etc.), that service can become slow or unresponsive. Without protection, your application keeps sending requests — piling up timeouts, wasting resources, and degrading user experience.
A circuit breaker monitors failures and automatically stops calling a failing service, giving it time to recover. It works like an electrical circuit breaker: when too many failures occur, the circuit "opens" and all requests fail fast without actually hitting the remote service.
| State | Behaviour |
|---|---|
| Closed | Normal operation. Requests pass through. Failures are counted. |
| Open | Requests are blocked immediately (fail fast). No calls reach the service. |
| Half-Open | A limited number of probe requests are allowed through to test recovery. |
Requirements
- PHP ^8.2
- Laravel ^11.0 or ^12.0
- gabrielanhaia/php-circuit-breaker ^3.0 (installed automatically)
Installation
Publish the configuration file:
Configuration
After publishing, the config lives at config/circuit_breaker.php.
Storage Driver
Choose where circuit state is persisted:
| Driver | Best for | Requirement |
|---|---|---|
redis |
Distributed / multi-server apps | ext-redis (phpredis) |
apcu |
Single-server, high performance | ext-apcu |
memcached |
Distributed caching | ext-memcached |
array |
Testing and local development | none |
Note: The Redis driver requires the phpredis PHP extension. Predis is not supported by the underlying storage adapter.
Default Thresholds
Per-Service Overrides
Different services can have different thresholds. Any key you omit falls back to the value in defaults:
Usage
Facade
Dependency Injection
HTTP Middleware
The circuit-breaker middleware wraps an entire route. It blocks requests when the circuit is open and automatically records successes and failures based on the HTTP status code.
Register the middleware on your routes:
When the circuit is open the middleware returns a JSON response:
with HTTP status 503 Service Unavailable.
Artisan Commands
Events
All circuit breaker events are dispatched through Laravel's event system, so you can listen to them like any other Laravel event:
| Event | Fired when |
|---|---|
FailureRecordedEvent |
A failure is recorded |
SuccessRecordedEvent |
A success is recorded |
CircuitOpenedEvent |
The circuit transitions to OPEN |
CircuitClosedEvent |
The circuit transitions to CLOSED |
CircuitHalfOpenEvent |
The circuit transitions to HALF_OPEN |
Every event exposes getServiceName(): string and getOccurredAt(): DateTimeImmutable.
Manual Override
Force a circuit state for maintenance windows or during an incident:
Upgrade from v1
See UPGRADE-2.0.md for step-by-step migration instructions.
Development
Support
If you find this package useful, consider supporting it:
License
MIT. See LICENSE for details.
All versions of laravel-circuit-breaker with dependencies
gabrielanhaia/php-circuit-breaker Version ^3.0
illuminate/contracts Version ^11.0||^12.0
illuminate/support Version ^11.0||^12.0