Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Circuit Breaker Bundle

Circuit Breaker Bundle Laravel Package

bizkit/circuit-breaker-bundle

View on GitHub
Deep Wiki
Context7

Symfony bundle integrating the circuit breaker pattern with Symfony HttpClient

Frequently asked questions about Circuit Breaker Bundle
Can I use this bundle directly in Laravel, or is it only for Symfony?
This bundle is designed for Symfony, but you can adapt its core logic (via `gabrielanhaia/php-circuit-breaker`) for Laravel. Replace Symfony’s `HttpClient` with Laravel’s `HttpClient` facade (or Guzzle), use Laravel’s `Cache` facade (PSR-6 compliant), and bridge Symfony’s `EventDispatcher` with Laravel’s `Events` system. The bundle’s decorator pattern works cross-framework.
How do I configure circuit breaker thresholds for Laravel’s HTTP clients?
Define thresholds in `config/circuit_breaker.php` using the same keys as the Symfony bundle (e.g., `threshold`, `timeout`, `half_open_timeout`). For Laravel’s `HttpClient`, wrap it in a decorator that uses the `php-circuit-breaker` library directly. Example: Set `threshold: 5` to trip after 5 consecutive failures.
Which Laravel cache drivers support PSR-6 for circuit breaker state storage?
Laravel’s Redis, Memcached, and database cache drivers (via `illuminate/cache`) are PSR-6 compliant. Ensure your chosen driver supports atomic operations for state updates (e.g., Redis `INCR` or `SETNX`). Avoid file-based caches, as they lack atomicity for circuit breaker state.
What exceptions trigger the circuit breaker in Laravel’s HttpClient?
Map Laravel’s `HttpClient` exceptions (e.g., `ConnectException`, `RequestException`, `ServerErrorException`) to the bundle’s config. Example: Configure `exceptions: [\Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface]` to trip the breaker on HTTP 4xx/5xx errors. Use `\GuzzleHttp\Exception\ConnectException` for Guzzle.
How do I handle Symfony events (e.g., `CircuitBreakerStateChanged`) in Laravel?
Use Laravel’s `Events` facade or install `symfony/event-dispatcher` to bridge Symfony events. For example, dispatch a Laravel event in a listener that subscribes to `CircuitBreakerStateChanged`. Alternatively, log events manually by tapping into the `php-circuit-breaker` library’s state changes.
What fallback should I use when the circuit is open in a Laravel app?
Define a retry strategy (e.g., exponential backoff) or graceful degradation (e.g., cached responses). For example, store successful responses in Laravel’s cache when the circuit is closed, then return cached data when open. Use `HttpClient::withOptions(['timeout' => 1])` to fail fast during retries.
Does this bundle work with Laravel’s queue system for delayed retries?
No, but you can integrate it manually. When the circuit is half-open, dispatch a Laravel job to retry the request after the timeout. Use `dispatch(new RetryFailedRequest($request))->delay(now()->addSeconds(10))` to implement exponential backoff.
Are there alternatives to this bundle for Laravel circuit breakers?
Yes. For Laravel, consider `spatie/laravel-circuitbreaker` (Laravel-native) or `php-circuit-breaker` directly with a custom decorator. If you need Symfony integration, this bundle is the closest fit, but you’ll need to adapt its components. Evaluate based on your stack: Symfony vs. Laravel-native solutions.
How do I test circuit breaker behavior in Laravel?
Mock Laravel’s `HttpClient` or Guzzle to simulate failures. Use PHPUnit to verify state transitions (e.g., `Closed` → `Open` after `threshold` failures). Test edge cases like concurrent requests or cache race conditions. Example: `HttpClient::fake([...])->throw(new ConnectException())->times(5);`.
Will this bundle impact performance in production?
Yes, circuit breakers add overhead to HTTP calls. Benchmark with tools like Blackfire or Laravel Debugbar to measure latency. Optimize by tuning thresholds (e.g., higher values for stable APIs) and using fast cache drivers (Redis). Monitor with Laravel’s `queue:failed` or custom logging for circuit breaker events.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle