PHPackages                             alex97lewis/laravel-circuit-breaker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. alex97lewis/laravel-circuit-breaker

ActiveLibrary[Caching](/categories/caching)

alex97lewis/laravel-circuit-breaker
===================================

A simple, drop-in circuit breaker implementation for Laravel applications with Redis caching and Artisan commands

v1.0.0(1y ago)157MITPHPPHP ^8.1

Since Jul 15Pushed 1y agoCompare

[ Source](https://github.com/Alex97Lewis/laravel-circuit-breaker)[ Packagist](https://packagist.org/packages/alex97lewis/laravel-circuit-breaker)[ Docs](https://github.com/alex97lewis/laravel-circuit-breaker)[ RSS](/packages/alex97lewis-laravel-circuit-breaker/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Laravel Circuit Breaker
=======================

[](#laravel-circuit-breaker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/a59574c6dcc3b5ceb529a3498214590463f98a852f60bc71ffe96bbbea9f6063/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c657839376c657769732f6c61726176656c2d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alex97lewis/laravel-circuit-breaker)[![Total Downloads](https://camo.githubusercontent.com/2c4eb0cefb241bf5971f598c61538ff008b8b306d44e0ac2570826903d510e3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c657839376c657769732f6c61726176656c2d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alex97lewis/laravel-circuit-breaker)

A simple, elegant circuit breaker implementation for Laravel applications with Redis caching and comprehensive Artisan command support.

Features
--------

[](#features)

- 🔄 **Three States**: Closed, Open, Half-Open with automatic transitions
- ⚡ **Redis-Powered**: Fast, reliable caching with Laravel's Redis integration
- 🎛️ **Configurable**: Failure thresholds, recovery timeouts, and more
- 📝 **Auto-Logging**: Comprehensive failure logging with context
- 🛠️ **Artisan Commands**: Test, monitor, and manage circuit breakers via CLI
- 🔍 **Dynamic Discovery**: No hardcoded circuit breaker names
- 🎨 **Laravel Integration**: Facades, helpers, and service container ready
- 📦 **Zero Dependencies**: Uses only Laravel's built-in components

Installation
------------

[](#installation)

Install via Composer:

```
composer require alex97lewis/laravel-circuit-breaker
```

The package will automatically register itself via Laravel's package discovery.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag=circuit-breaker-config
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Alex97Lewis\CircuitBreaker\CircuitBreaker;

$circuitBreaker = new CircuitBreaker('api-service');

try {
    $result = $circuitBreaker->call(function() {
        // Your risky operation here
        return Http::get('https://external-api.com/data');
    });
} catch (CircuitBreakerOpenException $e) {
    // Circuit is open, handle gracefully
    return $fallbackData;
}
```

### Using Helper Functions

[](#using-helper-functions)

```
// Simple helper
$result = with_circuit_breaker(function() {
    return Http::get('https://external-api.com/data');
}, 'api-service');

// Get circuit breaker instance
$cb = circuit_breaker('database-service', [
    'failure_threshold' => 3,
    'recovery_timeout' => 30
]);
```

### Using Facade

[](#using-facade)

```
use Alex97Lewis\CircuitBreaker\CircuitBreakerFacade as CircuitBreaker;

$result = CircuitBreaker::call(function() {
    return SomeService::riskyOperation();
});

// Check state
if (CircuitBreaker::isAvailable()) {
    // Safe to proceed
}
```

Configuration
-------------

[](#configuration)

Environment variables:

- `CIRCUIT_BREAKER_FAILURE_THRESHOLD=5` - Failures before opening
- `CIRCUIT_BREAKER_RECOVERY_TIMEOUT=60` - Seconds before retry
- `CIRCUIT_BREAKER_TIMEOUT=30` - Operation timeout
- `CIRCUIT_BREAKER_LOG_FAILURES=true` - Log failures

States
------

[](#states)

- **Closed**: Normal operation
- **Open**: Failing fast, rejecting calls
- **Half-Open**: Testing if service recovered

Features
--------

[](#features-1)

- ✅ Zero dependencies (uses Laravel Cache)
- ✅ Named circuit breakers for different services
- ✅ Configurable thresholds and timeouts
- ✅ Automatic logging
- ✅ Helper functions and facade
- ✅ Drop-in modular design
- ✅ Built-in Artisan commands for testing and management

Artisan Commands
----------------

[](#artisan-commands)

The module includes several Artisan commands for testing and managing circuit breakers:

### Test Circuit Breaker

[](#test-circuit-breaker)

```
php artisan circuit-breaker:test [name] [--threshold=2] [--timeout=1]
```

Test a circuit breaker with simulated failures.

### Check Status

[](#check-status)

```
php artisan circuit-breaker:status [name]
```

Show the status of a specific circuit breaker or all circuit breakers.

### Reset Circuit Breaker

[](#reset-circuit-breaker)

```
php artisan circuit-breaker:reset {name} [--all]
```

Reset a circuit breaker to closed state or reset all circuit breakers.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance47

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

398d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/daaa0afe004390bfa2e6edd188b6b29b98c7118a22fd1c2acfe16e2cd4e6e558?d=identicon)[Alex97Lewis](/maintainers/Alex97Lewis)

---

Top Contributors

[![Alex97Lewis](https://avatars.githubusercontent.com/u/22716817?v=4)](https://github.com/Alex97Lewis "Alex97Lewis (1 commits)")

---

Tags

laravelrediscircuit breakerfault toleranceresiliencereliability

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alex97lewis-laravel-circuit-breaker/health.svg)

```
[![Health](https://phpackages.com/badges/alex97lewis-laravel-circuit-breaker/health.svg)](https://phpackages.com/packages/alex97lewis-laravel-circuit-breaker)
```

###  Alternatives

[mike-bronner/laravel-model-caching

Automatic caching for Eloquent models.

2.4k161.4k2](/packages/mike-bronner-laravel-model-caching)[propaganistas/laravel-disposable-email

Disposable email validator

6023.2M7](/packages/propaganistas-laravel-disposable-email)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k16.3M154](/packages/laravel-pulse)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.3M74](/packages/spatie-laravel-responsecache)[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M319](/packages/laravel-ai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
