PHPackages                             syastrebov/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. syastrebov/laravel-circuit-breaker

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

syastrebov/laravel-circuit-breaker
==================================

Laravel package for circuit breaker.

v0.0.9(4mo ago)01.0k↓86.9%MITPHPPHP ^8.3CI passing

Since Jan 30Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/syastrebov/laravel-circuit-breaker)[ Packagist](https://packagist.org/packages/syastrebov/laravel-circuit-breaker)[ RSS](/packages/syastrebov-laravel-circuit-breaker/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (10)Versions (10)Used By (0)

PHP Circuit Breaker implementation for microservices and API calls.

Laravel package for  library.

Install
-------

[](#install)

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

php artisan vendor:publish --provider="CircuitBreaker\\Laravel\\CircuitBreakerServiceProvider"
```

Config
------

[](#config)

```
return [

    // Supported drivers (redis, predis, memcached, database, memory)
    'driver' => 'redis',

    'logger' => [
        'channel' => '',
    ],

    'connections' => [
        'redis' => [
            'connection' => 'default',
        ],
        'database' => [
            'connection' => '',
            'table' => 'circuit_breaker',
        ],
    ],

    'configs' => [
        'default' => [
            'retries' => 3,
            'closed_threshold' => 3,
            'half_open_threshold' => 3,
            'retry_interval' => 1000,
            'open_timeout' => 60,
            'fallback_or_null' => false,
        ],
    ],
];
```

Usage
-----

[](#usage)

### Simple example:

[](#simple-example)

#### Default config:

[](#default-config)

```
use CircuitBreaker\Laravel\Facades\CircuitBreaker;

public function request(): string
{
    try {
        // creates default config
        return CircuitBreaker::make()->run('test', static function () {
            return '{"response": "data"}';
        });
    } catch (UnableToProcessException $e) {
        // handle exception
    }
}
```

#### Custom config:

[](#custom-config)

circuit-breaker.php

```
return [

    'configs' => [
        'api' => [
            'retries' => 3,
            'closed_threshold' => 3,
            'half_open_threshold' => 3,
            'retry_interval' => 1000,
            'open_timeout' => 60,
            'fallback_or_null' => false,
        ],
    ],
];
```

```
use CircuitBreaker\Laravel\Facades\CircuitBreaker;

public function request(): string
{
    try {
        return CircuitBreaker::make('api')->run('test', static function () {
            return '{"response": "data"}';
        });
    } catch (UnableToProcessException $e) {
        // handle exception
    }
}
```

### Stub response:

[](#stub-response)

```
use CircuitBreaker\Laravel\Facades\CircuitBreaker;

public function request(): string
{
    return CircuitBreaker::make()->run(
        '{endpoint}',
        static function () {
            return (string) (new Client)->get('https://domain/api/{endpoint}')->getBody();
        },
        static function () {
            return json_encode([
                'data' => [
                    'key' => 'default value',
                ],
            ]);
        }
    );
}
```

### Cache response:

[](#cache-response)

```
use CircuitBreaker\Laravel\Facades\CircuitBreaker;

public function request(): string
{
    return CircuitBreaker::make()->run(
        '{endpoint}',
        static function () {
            $response = (string) (new Client)->get('https://{domain}/api/{endpoint}')->getBody();
            Cache::set('circuit.{endpoint}.response', $response);

            return $response;
        },
        static function () {
            return Cache::get('circuit.{endpoint}.response');
        }
    );
}
```

Using CacheableCircuitBreaker:

```
use CircuitBreaker\Laravel\Facades\CircuitBreaker;

public function request(): string
{
    return CircuitBreaker::makeCacheable()->run('{endpoint}', static function () {
        return (string) (new Client)->get('https://{domain}/api/{endpoint}')->getBody();
    });
}
```

Multiple instances
------------------

[](#multiple-instances)

circuit-breaker.php

```
return [

    'configs' => [
        'api1' => [
            'retries' => 3,
            'closed_threshold' => 3,
            'half_open_threshold' => 3,
            'retry_interval' => 1000,
            'open_timeout' => 60,
            'fallback_or_null' => false,
        ],
        'api2' => [
            'retries' => 5,
            'closed_threshold' => 5,
            'half_open_threshold' => 5,
            'retry_interval' => 3000,
            'open_timeout' => 120,
            'fallback_or_null' => false,
        ],
    ],
];
```

```
use CircuitBreaker\Laravel\Facades\CircuitBreaker;

public function requestApi1(): string
{
    return CircuitBreaker::makeCacheable('api1')->run('/users', static function () {
        return (string) (new Client)->get('https://{api1.domain}/api/users')->getBody();
    });
}

public function requestApi2(): string
{
    return CircuitBreaker::makeCacheable('api2')->run('/users', static function () {
        return (string) (new Client)->get('https://{api2.domain}/api/users')->getBody();
    });
}
```

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance74

Regular maintenance activity

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

Every ~1 days

Total

9

Last Release

147d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1681915?v=4)[syastrebov](/maintainers/syastrebov)[@syastrebov](https://github.com/syastrebov)

---

Top Contributors

[![syastrebov](https://avatars.githubusercontent.com/u/1681915?v=4)](https://github.com/syastrebov "syastrebov (17 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[illuminate/events

The Illuminate Events package.

13557.0M2.1k](/packages/illuminate-events)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/session

The Illuminate Session package.

9939.3M849](/packages/illuminate-session)

PHPackages © 2026

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