Download the PHP package cmatosbc/alecto without Composer
On this page you can find all versions of the php package cmatosbc/alecto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cmatosbc/alecto
More information about cmatosbc/alecto
Files in cmatosbc/alecto
Package alecto
Short Description A robust PHP Circuit Breaker implementation with type safety and modern features
License MIT
Informations about the package alecto
Alecto - PHP Circuit Breaker Library
A robust PHP implementation of the Circuit Breaker pattern with type safety, metrics tracking, and configurable behavior.
In the depths of Greek mythology, Alecto, one of the three Erinyes or Furies, emerges as a formidable figure. These divine beings were born from the blood of the castrated Uranus, embodying the relentless pursuit of vengeance. Alecto, in particular, is known for her unwavering determination and relentless pursuit of justice.
Her story offers a powerful metaphor for a circuit breaker pattern in programming. Just as Alecto intervenes to stop a cycle of violence and retribution, a circuit breaker interrupts a process to prevent it from spiraling out of control. In the realm of software, this might mean stopping an infinite loop, halting a runaway process, or preventing a system from crashing.
By drawing inspiration from Alecto, we can design circuit breaker patterns that are:
- Swift and decisive: Like the Erinyes, a circuit breaker must act quickly to prevent further damage.
- Relentless: Once activated, a circuit breaker should remain in effect until the underlying issue is resolved.
- Just: A circuit breaker should be used judiciously, only when necessary to protect the system.
๐ Features
- Type-safe implementation using PHP 8.1+
- Configurable failure and success thresholds
- Operation timeout handling
- Fallback mechanism support
- Metrics tracking
- State transition management
- PSR-3 compatible logging support
๐ฆ Installation
Install via Composer:
Requirements:
- PHP 8.1 or higher
ext-pcntl
extensionext-posix
extension
๐ Quick Start
๐ Circuit States
The circuit breaker operates in three states:
CLOSED (Normal Operation)
- All requests are allowed through
- Failures are counted
- When failures reach
failureThreshold
, transitions to OPEN
OPEN (Failure Prevention)
- All requests are immediately rejected
- After
resetTimeout
seconds, transitions to HALF-OPEN - Supports fallback responses during rejection
HALF-OPEN (Recovery Attempt)
- Limited requests are allowed through
- Successes are counted
- After
successThreshold
successes, transitions to CLOSED - Any failure returns to OPEN state
๐ Metrics Tracking
The circuit breaker tracks key metrics:
๐ฏ Real-World Examples
1. API Client Protection
2. Database Query Protection
3. Microservice Communication
๐ Framework Integration
Symfony Integration
Laravel Integration
โ๏ธ Advanced Configuration
Custom Timeout Handling
Adding Logging
๐งช Testing
Run the test suite:
The tests demonstrate:
- State transition behavior
- Failure counting
- Success threshold management
- Timeout handling
- Metrics accuracy
๐ค Contributing
- Fork the repository
- Create a feature branch
- Write tests for new features
- Submit a pull request
๐ License
This library is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
All versions of alecto with dependencies
ext-pcntl Version *
ext-posix Version *