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

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

luucasfzs/laravel-circuit-breaker
=================================

A circuit breaker pattern implementation for the Laravel framework

1.0.0(3y ago)031MITPHPPHP &gt;= 7.1

Since Mar 22Pushed 3y ago1 watchersCompare

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

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

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

[](#laravel-circuit-breaker)

An implementation of the Circuit Breaker pattern for Laravel Framework 5.6.

[![Latest Version on Packagist](https://camo.githubusercontent.com/37b11593ab5e294f10e0975db24a6ef3614f185bdb3ddc8760a168b3e46a25f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4c7575636173667a732f6c61726176656c2d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/Luucasfzs/laravel-circuit-breaker)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a13d41c495159cb4bdaaf0219001434703eb25129e849c68a03f93db0ac3a4e3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4c7575636173667a732f6c61726176656c2d636972637569742d627265616b65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Luucasfzs/laravel-circuit-breaker)[![Quality Score](https://camo.githubusercontent.com/c0e9663326a9c52539765b20a7c95853ceb1aa23085c500db5868bff04ad0a1e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4c7575636173667a732f6c61726176656c2d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Luucasfzs/laravel-circuit-breaker)[![StyleCI](https://camo.githubusercontent.com/6a9331a410c713cb86481d752ebf321fec290e344170ea0397cd4645fe99f37a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133303032323835352f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/130022855)

If you need an easy to use implementation of the [circuit breaker pattern](https://martinfowler.com/bliki/CircuitBreaker.html) for your Laravel application, you're in the right place.

**Note:** this package is compatible with Laravel 5.6. Other/previous versions are not tested yet.

Install
-------

[](#install)

You can use Composer to install the package for your project.

```
$ composer require luucasfzs/laravel-circuit-breaker
```

Don't worry about service providers and façades: Laravel can auto discover the package without doing nothing!

Just remember to **publish the config file** with

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

You will always use a single class (`CircuitBreaker` façade or `CircuitBreakerManager` class if you want to inject it) to work with this package.

Here's the methods reference:

### isAvailable(string $identifier) : bool

[](#isavailablestring-identifier--bool)

Returns `true` if the `$identifier` service is currently available. Returns `false` otherwise.

**Note:** you can use whatever you want as identifier. I like to use the `MyClass::class` name when possible.

### reportFailure(string $identifier) : void

[](#reportfailurestring-identifier--void)

Reports a failed attempt for the `$identifier` service. Take a look at the Configuration section below to know how attempts and failure times are managed.

### reportSuccess(string $identifier) : void

[](#reportsuccessstring-identifier--void)

Reports a successful attempt for the `$identifier` service. You can use it to mark a service as available and remove the "failed" status from it.

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

[](#configuration)

### Defaults

[](#defaults)

By editing the `config/circuit_breaker.php` config file contents you will able to tweak the circuit breaker in a way that is more suitable for your needs.

You have three values under the `default` item:

```
