bizkit/circuit-breaker-bundle
HttpClient, Cache, and EventDispatcher components. This makes it a natural fit for Laravel applications using Laravel Symfony Bridge (e.g., symfony/http-client, symfony/cache, symfony/event-dispatcher).HttpClient aligns well with Laravel’s service container and HTTP client abstractions (e.g., GuzzleHttp, Symfony HttpClient).Cache facade (PSR-6 compliant via illuminate/cache) can serve as the storage backend, reducing external dependencies.HttpClient, EventDispatcher), which can be mapped to Laravel equivalents:
symfony/http-client with Laravel’s HttpClient facade (or Guzzle).Cache facade (PSR-6) instead of Symfony’s CachePool.EventDispatcher with Laravel’s Events system (via symfony/event-dispatcher or native Event facade).gabrielanhaia/php-circuit-breaker, which is stable but niche. Laravel’s ecosystem lacks a native circuit breaker, so this fills a gap.| Risk Area | Assessment | Mitigation Strategy |
|---|---|---|
| Symfony-Laravel Gap | Bundle assumes Symfony’s HttpClient and CachePool interfaces. |
Abstract Symfony-specific code via adapters (e.g., wrap HttpClient in a decorator). |
| Event Dispatcher | Symfony’s EventDispatcher is not natively in Laravel. |
Use symfony/event-dispatcher or Laravel’s Events with a bridge layer. |
| Cache Backend | PSR-6 cache (e.g., Redis, Memcached) must be configured. | Laravel’s Cache facade already supports PSR-6; minimal config changes needed. |
| Testing | Low test coverage (0 stars, unproven). | Write integration tests for Laravel’s HttpClient + Cache integration. |
| Performance | Circuit breaker adds overhead to HTTP calls. | Benchmark with high-traffic endpoints to validate latency impact. |
HttpClient facade (Symfony HttpClient wrapper)?
Http client?HttpClient throws ConnectException, RequestException, etc.—map these to the bundle’s config.CircuitBreakerStateChanged) be handled in Laravel?
Events system or a listener adapter for Symfony events.| Laravel Component | Bundle Equivalent | Integration Strategy |
|---|---|---|
HttpClient (Symfony) |
HttpClient decorator |
Use Laravel’s HttpClient facade (Symfony HttpClient under the hood). |
Cache (PSR-6) |
PSR-6 cache backend | Leverage Laravel’s Cache::store('redis') or Cache::store('database'). |
Events |
Symfony EventDispatcher |
Option 1: Use symfony/event-dispatcher package. |
| Option 2: Create a Laravel event listener that subscribes to circuit breaker events. | ||
Config |
Bundle configuration (YAML/XML) | Use Laravel’s config/circuit_breaker.php with the same keys as the bundle. |
Phase 1: Dependency Setup
composer require bizkit/circuit-breaker-bundle gabrielanhaia/php-circuit-breaker symfony/http-client symfony/cache symfony/event-dispatcher
php-circuit-breaker) with Laravel’s HttpClient.Phase 2: Configuration
config/circuit_breaker.php:
return [
'clients' => [
'main' => [
'threshold' => 5, // Failures before tripping
'timeout' => 30, // Open state duration (seconds)
'half_open_timeout' => 10, // Half-open state duration
'exceptions' => [
\Symfony\Contracts\HttpClient\Exception\ClientException::class,
\Symfony\Contracts\HttpClient\Exception\ServerException::class,
],
],
'scoped' => [
// Per-client configs
],
],
'cache' => env('CACHE_DRIVER', 'redis'), // PSR-6 cache driver
];
Phase 3: HttpClient Decorator
HttpClient:
use GabrielAnhia\CircuitBreaker\CircuitBreaker;
use GabrielAnhia\CircuitBreaker\CircuitBreakerFactory;
use Illuminate\Support\Facades\Http;
use Symfony\Component\HttpClient\NativeHttpClient;
public function register()
{
$cache = Cache::store(config('circuit_breaker.cache'));
$factory = new CircuitBreakerFactory($cache);
$httpClient = new NativeHttpClient();
$decoratedClient = $factory->create($httpClient, config('circuit_breaker.clients.main'));
Http::macro('withCircuitBreaker', function () use ($decoratedClient) {
return new HttpClient($decoratedClient);
});
}
Phase 4: Event Handling (Optional)
use GabrielAnhia\CircuitBreaker\Event\CircuitBreakerStateChanged;
Event::listen(CircuitBreakerStateChanged::class, function ($event) {
Log::info("Circuit breaker state changed: {$event->getState()}");
});
illuminate/http-client).Events or Symfony’s EventDispatcher.config/circuit_breaker.php file).php-circuit-breaker) requires monitoring.HttpClient changes.telescope or laravel-debugbar to inspect circuit breaker state.CircuitBreakerStateChanged events for observability.'clients' => [
'problematic_api' => ['enabled' => false],
]
How can I help you explore Laravel packages today?