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

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

paymaxi/circuit-breaker
=======================

PHP Circuit Breaker component

v0.1.1(9y ago)212MITPHPPHP &gt;=7.0

Since Feb 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dzubchik/php-circuit-breaker)[ Packagist](https://packagist.org/packages/paymaxi/circuit-breaker)[ Docs](https://github.com/dzubchi/php-circuit-breaker)[ RSS](/packages/paymaxi-circuit-breaker/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

What is Circuit Breaker
=======================

[](#what-is-circuit-breaker)

[![Build Status](https://camo.githubusercontent.com/dd8a81e196e7cb29abfad289239b24784845690100db996878181fdb46a6f03e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f647a75626368696b2f7068702d636972637569742d627265616b65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/dzubchik/php-circuit-breaker)[![Quality Score](https://camo.githubusercontent.com/a8c3bdcf6351b26ed25760f3961dc7e57666b16a75da0b554f4153665e3f3e76/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f647a75626368696b2f7068702d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/dzubchik/php-circuit-breaker)[![Coverage Status](https://camo.githubusercontent.com/586a6be08e4ed05a6a0083c6f38e872f34c06a9ad81bd85189595a6bcd0e16fe/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f647a75626368696b2f7068702d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/dzubchik/php-circuit-breaker/code-structure)[![Latest Version on Packagist](https://camo.githubusercontent.com/9cd5a4d200f175d4baa30e9c2f5b93853a89d8d7f5dcae605f760404018abb15/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f647a75626368696b2f7068702d636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paymaxi/circuit-breaker)[![Total Downloads](https://camo.githubusercontent.com/cb26edf6d16da786fd773fa3b48bc686b9935f0de9566cebf2dcda1d9c65ee07/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7061796d6178692f636972637569742d627265616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/paymaxi/circuit-breaker)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

A component helping you gracefully handle outages and timeouts of external services (usually remote, 3rd party services).

It is a library providing extremely easy to use circuit breaker component. It does not require external dependencies and it has default storage implementations for APC and Memcached but can be extended multiple ways. See [more](http://microservices.io/patterns/reliability/circuit-breaker.html).

Frameworks support
==================

[](#frameworks-support)

This library does not require any particular PHP framework, all you need is PHP 5.3 or higher.

Motivation &amp; Benefits
=========================

[](#motivation--benefits)

- Allow application to detect failures and adapt its behaviour without human intervention.
- Increase robustness of services by addinf fail-safe functionality into modules.

Installation
============

[](#installation)

You can download sources and use them with your autoloader or you can use composer in which case all you needs is a require like this:

```
"require": {
    "paymaxi\circuit-breaker": "*"
},

```

After that you should update composer dependencies and you are good to go.

Use Case - Non-Critical Feature
-------------------------------

[](#use-case---non-critical-feature)

- Your application has an Non-Critical Feature like: user tracking, stats, recommendations etc
- The optional feature uses remote service that causes outages of your application.
- You want to keep application and core processes available when "Non-Critical Feature" fails.

Code of your application could look something like:

```
    $factory = new Paymaxi\Component\CircuitBreaker\Factory();
    $circuitBreaker = $factory->getSingleApcInstance(30, 300);

    $userProfile = null;
    if( $circuitBreaker->isAvailable("UserProfileService") ){
        try{
            $userProfile = $userProfileService->loadProfileOrWhatever();
            $circuitBreaker->reportSuccess("UserProfileService");
        }catch( UserProfileServiceConnectionException $e ){
            // network failed - report it as failure
            $circuitBreaker->reportFailure("UserProfileService");
        }catch( Exception $e ){
            // something went wrong but it is not service's fault, dont report as failure
        }
    }
    if( $userProfile === null ){
        // for example, show 'System maintenance, you cant login now.' message
        // but still let people buy as logged out customers.
    }
```

Use Case - Payment Gateway
--------------------------

[](#use-case---payment-gateway)

- Web application depends on third party service (for example a payment gateway).
- Web application needs to keep track when 3rd party service is unavailable.
- Application can not become slow/unavailable, it has to tell user that features are limited or just hide them.
- Application uses circuit breaker before checkout page rendering and if particular payment gateway is unavailable payment option is hidden from the user.

As you can see that is a very powerful concept of selectively disabling feautres at runtime but still allowing the core business processes to be uninterrupted.

Backend talking to the payment service could look like this:

```
    $factory = new Paymaxi\Component\CircuitBreaker\Factory();
    $circuitBreaker = $factory->getSingleApcInstance(30, 300);

    try{
        // try to process the payment
        // then tell circuit breaker that it went well
        $circuitBreaker->reportSuccess("PaymentOptionOne");
    }catch( SomePaymentConnectionException $e ){
        // If you get network error report it as failure
        $circuitBreaker->reportFailure("PaymentOptionOne");
    }catch( Exception $e ){
        // in case of your own error handle it however it makes sense but
        // dont tell circuit breaker it was 3rd party service failure
    }
```

Since you are recording failed and successful operations you can now use them in the front end as well to hide payment options that are failing.

Frontend rendering the available payment options could look like this:

```
    $factory = new Paymaxi\Component\CircuitBreaker\Factory();
    $circuitBreaker = $factory->getSingleApcInstance(30, 300);

    if ($circuitBreaker->isAvailable("PaymentOptionOne")) {
        // display the option
    }
```

Features
========

[](#features)

- Track multiple services through a single Circuit Breaker instance.
- Pluggable backend adapters, provided APC and Memcached by default.
- Customisable service thresholds. You can define how many failures are necessary for service to be considered down.
- Customisable retry timeout. You do not want to disable the service forever. After provided timeout circuit breaker will allow a single process to attempt

Performance Impact
==================

[](#performance-impact)

Overhead of the Circuit Breaker is negligible.

APC implementation takes roughly 0.0002s to perform isAvailable() and then reportSuccess() or reportFailure().

Memcache adapter is in range of 0.0005s when talking to the local memcached process.

The only potential performance impact is network connection time. If you chose to use remote memcached server or implement your own custom StorageAdapter.

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.9% 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 ~738 days

Total

3

Last Release

3400d ago

PHP version history (2 changes)0.0.1PHP &gt;=5.3.0

v0.1.1PHP &gt;=7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d3834393f8093286a88277f704ad689eeb41333ed2d94ed12eb83e622901286?d=identicon)[dzubchik](/maintainers/dzubchik)

---

Top Contributors

[![ejsmont-artur](https://avatars.githubusercontent.com/u/345911?v=4)](https://github.com/ejsmont-artur "ejsmont-artur (29 commits)")[![dzubchik](https://avatars.githubusercontent.com/u/2685761?v=4)](https://github.com/dzubchik "dzubchik (4 commits)")

---

Tags

circuit-breakermicroservicesphperror handlingcircuit breakergraceful

### Embed Badge

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

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

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[ejsmont-artur/php-circuit-breaker

PHP Circuit Breaker component

168993.3k4](/packages/ejsmont-artur-php-circuit-breaker)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[oat-sa/generis

TAO generis library

10144.6k109](/packages/oat-sa-generis)[firevel/firebase-authentication

Firebase authentication driver for Laravel

2224.5k2](/packages/firevel-firebase-authentication)

PHPackages © 2026

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