PHPackages                             hadinem/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. hadinem/circuit-breaker

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

hadinem/circuit-breaker
=======================

Laravel circuit breaker package

031PHP

Since May 12Pushed 12mo agoCompare

[ Source](https://github.com/hadinem/laravel-circuit-breaker-bv)[ Packagist](https://packagist.org/packages/hadinem/circuit-breaker)[ RSS](/packages/hadinem-circuit-breaker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

🚨 THIS PACKAGE HAS BEEN ABANDONED 🚨

I no longer use Laravel and cannot justify the time needed to maintain this package. That's why I have chosen to abandon it. Feel free to fork my code and maintain your own copy.

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

[](#laravel-circuit-breaker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8e616bf82fac8668c1d4ca20c3091010792df87b2a311115c3d28a7dacf38123/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f627674746572666c792f6c61726176656c2d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bvtterfly/laravel-circuit-breaker) [![GitHub Tests Action Status](https://camo.githubusercontent.com/a0b6d89467341c5bb018100cd405213e5483f74aa14507d4ea94f3283806d533/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f627674746572666c792f6c61726176656c2d636972637569742d627265616b65722f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/bvtterfly/laravel-circuit-breaker/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://camo.githubusercontent.com/5a75393764f8edc1a678452849a1138cf4afa013b84b12c3cf4e758ce2b0a1d1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f627674746572666c792f6c61726176656c2d636972637569742d627265616b65722f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/bvtterfly/laravel-circuit-breaker/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain) [![Total Downloads](https://camo.githubusercontent.com/aea91dfffc69f8300ce5d2bdd01ef3d79300abc559d6f2159aedfa0aa2479ab0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f627674746572666c792f6c61726176656c2d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bvtterfly/laravel-circuit-breaker)

This package is a simple implementation of circuit breaker pattern for laravel. It protects your application from failures of its service dependencies.

Resources about the circuit breaker pattern:

-
-

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

[](#installation)

You can install the package via composer:

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

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    // Here you may specify which of your cache stores you wish to use as your default store.
    'store' => config('cache.default'),

    // length of interval (in seconds) over which it calculates the error rate
    'time_window' => 60,

    // the number of errors to encounter within a given timespan before opening the circuit
    'error_threshold' => 10,

    // the amount of time until the circuit breaker will try to query the resource again
    'error_timeout' => 300,

    // the timeout for the circuit when it is in the half-open state
    'half_open_timeout' => 150,

    // the amount of consecutive successes for the circuit to close again
    'success_threshold' => 1,
];
```

Usage
-----

[](#usage)

Your application may have multiple services, so you will have to get a circuit breaker for each service:

```
use Bvtterfly\LaravelCircuitBreaker\Facades\CircuitBreaker;
$circuit = CircuitBreaker::service('my-service');
// or you can override default configuration:
$circuit = CircuitBreaker::service('my-service', [
    'time_window' => 120,
    'success_threshold' => 3,
]);
```

#### Three states of circuit breaker

[](#three-states-of-circuit-breaker)

[![](https://user-images.githubusercontent.com/1885716/53690408-4a7f3d00-3dad-11e9-852c-0e082b7b9636.png)](https://user-images.githubusercontent.com/1885716/53690408-4a7f3d00-3dad-11e9-852c-0e082b7b9636.png)

You can then determine whether a service is available or not.

```
// Check circuit status for service
if (! $circuit->isAvailable()) {
    // Service isn't available
}
```

Service is available if it's CLOSED or HALF\_OPEN. Then, you should call your service, depending on the response. You can mark it as a success or failure to update the circuit status.

```
try {
    callAPI();
    $circuit->markSuccess();
} catch (\Exception $e) {
    // If an error occurred, it must be recorded as failed.
    $circuit->markFailed();
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [ARI](https://github.com/bvtterfly)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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.

### Community

Maintainers

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

---

Top Contributors

[![bvtterfly](https://avatars.githubusercontent.com/u/99682351?v=4)](https://github.com/bvtterfly "bvtterfly (12 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![hadinem](https://avatars.githubusercontent.com/u/36122376?v=4)](https://github.com/hadinem "hadinem (4 commits)")

### Embed Badge

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

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

PHPackages © 2026

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