PHPackages                             love-oss/resiliency - 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. love-oss/resiliency

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

love-oss/resiliency
===================

A circuit breaker implementation for PHP 7.4+

2.3(4y ago)7619.1k↓38.9%7[6 issues](https://github.com/loveOSS/resiliency/issues)MITPHPPHP ^7.4|^8.0

Since May 11Pushed 4y ago3 watchersCompare

[ Source](https://github.com/loveOSS/resiliency)[ Packagist](https://packagist.org/packages/love-oss/resiliency)[ RSS](/packages/love-oss-resiliency/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (16)Used By (0)

Resiliency, an implementation for resilient and modern PHP applications
=======================================================================

[](#resiliency-an-implementation-for-resilient-and-modern-php-applications)

[![codecov](https://camo.githubusercontent.com/f152b11058ac0bb34517623ccee21fbb7641fd7ddd79ac2df1caded5b042e20f/68747470733a2f2f636f6465636f762e696f2f67682f6c6f76654f53532f726573696c69656e63792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/loveOSS/resiliency) [![PHPStan](https://camo.githubusercontent.com/c4868354f3efc5a6b77b3ad340e9a839d8ea95c63b80c514ec050966ae3c83f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c2532306d61782d627269676874677265656e2e7376673f7374796c653d666c6174266c6f676f3d706870)](https://shields.io/#/) [![Psalm](https://camo.githubusercontent.com/96b905dc00aa280becfa54dd6358d21c63dd7c8c7a7ff93810ccff917e5954a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5073616c6d2d4c6576656c2532304d61782d627269676874677265656e2e7376673f7374796c653d666c6174266c6f676f3d706870)](https://shields.io/#/) [![Build Status](https://camo.githubusercontent.com/cd7ddd366c057de418431f07ff54ec571aba1f5e63f2c714bbc29ff94b07699b/68747470733a2f2f7472617669732d63692e636f6d2f6c6f76654f53532f726573696c69656e63792e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/loveOSS/resiliency)

Main principles
---------------

[](#main-principles)

[![circuit breaker](https://user-images.githubusercontent.com/1247388/49721725-438bd700-fc63-11e8-8498-82ca681b15fb.png)](https://user-images.githubusercontent.com/1247388/49721725-438bd700-fc63-11e8-8498-82ca681b15fb.png)

This library is compatible with PHP 7.4+.

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

[](#installation)

```
composer require love-oss/resiliency

```

Use
---

[](#use)

You need to configure a system for the Circuit Breaker:

- the **failures**: define how many times we try to access the service;
- the **timeout**: define how long we wait (in ms) before consider the service unreachable;
- the **stripped timeout**: define how long we wait (in ms) before consider the service unreachable, once we're in half open state;
- the **threshold**: define how long we wait (in ms) before trying to access again the service;
- the (HTTP|HTTPS) **client** that will be used to reach the services;
- the **fallback** callback will be used if the distant service is unreachable when the Circuit Breaker is Open (means "is used").

> You'd better return the same type of response expected from your distant call.

```
use Resiliency\MainCircuitBreaker;
use Resiliency\Systems\MainSystem;
use Resiliency\Storages\SimpleArray;
use Resiliency\Clients\SymfonyClient;
use Symfony\Component\HttpClient\HttpClient;

$client = new SymfonyClient(HttpClient::create());

$mainSystem = MainSystem::createFromArray([
    'failures' => 2,
    'timeout' => 100,
    'stripped_timeout' => 200,
    'threshold' => 10000,
], $client);

$storage = new SimpleArray();

// Any PSR-14 Event Dispatcher implementation.
$dispatcher = new Symfony\Component\EventDispatcher\EventDispatcher;

$circuitBreaker = new MainCircuitBreaker(
    $mainSystem,
    $storage,
    $dispatcher
);

/**
 * @var Service $service
 */
$fallbackResponse = function ($service) {
    return '{}';
};

$circuitBreaker->call(
    'https://api.domain.com',
    $fallbackResponse,
    [
        'query' => [
            '_token' => '123456789',
        ]
    ]
);
```

### Clients

[](#clients)

Resiliency library supports both [Guzzle (v6 &amp; v7)](http://docs.guzzlephp.org/en/stable/index.html) and HttpClient Component from [Symfony (v4 &amp; v5)](https://symfony.com/doc/current/components/http_client.html).

### Monitoring

[](#monitoring)

This library provides a minimalist system to help you monitor your circuits.

```
$monitor = new SimpleMonitor();

// Collect information while listening
// to some circuit breaker events...
function listener(Event $event) {
    $monitor->add($event);
};

// Retrieve a complete report for analysis or storage
$report = $monitor->getReport();
```

Tests
-----

[](#tests)

```
composer test

```

Code quality
------------

[](#code-quality)

This library has high quality standards:

```
composer cs-fix && composer phpstan && composer psalm && composer phpqa

```

We also use [PHPQA](https://github.com/EdgedesignCZ/phpqa#phpqa) to check the Code quality during the CI management of the contributions:

```
composer phpqa

```

I've heard of the PrestaShop Circuit Breaker: what library should I use ?
-------------------------------------------------------------------------

[](#ive-heard-of-the-prestashop-circuit-breaker-what-library-should-i-use-)

Welcome, that's an interesting question !

Above all, I must say that I'm the former author of the PrestaShop [Circuit Breaker](https://github.com/PrestaShop/circuit-breaker) library and I have decided to fork my own library to be able to improve it without the constraints of the PrestaShop CMS main project.

As of now (June, 2021), these libraries have a lot in common !

They share almost the same API, and the PrestaShop Core Team have created multiple implementations of [Circuit Breaker interface](https://github.com/PrestaShop/circuit-breaker/blob/develop/src/AdvancedCircuitBreaker.php) and [Factory](https://github.com/PrestaShop/circuit-breaker/blob/develop/src/AdvancedCircuitBreakerFactory.php) :

- SimpleCircuitBreaker
- AdvancedCircuitBreaker
- PartialCircuitBreaker
- SymfonyCircuitBreaker

1. They maintain a version compatible with PHP 7.2+ and Symfony 4 but not (yet ?) with PHP 8 and Symfony 5 ;
2. They have a dependency on their own package named [php-dev-tools](https://github.com/PrestaShop/php-dev-tools) ;
3. They maintain an implementation of [Storage](https://github.com/PrestaShop/circuit-breaker/blob/v4.0.0/src/Storage/DoctrineCache.php) using Doctrine Cache library ;
4. They don't have a Symfony HttpClient implementation ;
5. For the events, I'm not sure as their implementation make the list difficult to establish ;
6. They don't provide a mecanism to reset and restore a Circuit Breaker ;
7. They don't provide a mecanism to monitor the activity of a Circuit Breaker ;
8. They have removed [Psalm](https://psalm.dev/) from their CI and they don't use [PHPQA](https://github.com/EdgedesignCZ/phpqa) ;
9. They have added `declare(strict_types=1);` on all the files ;
10. They don't declare a `.gitattributes` file, this means that all tests are downloaded when [we require](https://madewithlove.com/blog/software-engineering/gitattributes/) their library ;

> All right ... but this don't tell me what library should I use in my project !

- If you need PHP 5.6, use Circuit Breaker v3
- If you need PHP 7.2, use Circuit Breaker v4
- If you need PHP 7.4+, use Resiliency
- If you need a library maintained by a team of developers, use PrestaShop
- If you trust [me](https://github.com/mickaelandrieu) to maintain this package *almost* all alone, use Resiliency !

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% 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 ~82 days

Recently: every ~139 days

Total

13

Last Release

1574d ago

Major Versions

0.5 → 1.02019-09-20

1.x-dev → 2.02021-03-30

PHP version history (2 changes)0.1PHP ^7.2

2.0PHP ^7.4|^8.0

### Community

Maintainers

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

---

Top Contributors

[![mickaelandrieu](https://avatars.githubusercontent.com/u/1247388?v=4)](https://github.com/mickaelandrieu "mickaelandrieu (121 commits)")[![jdreesen](https://avatars.githubusercontent.com/u/424602?v=4)](https://github.com/jdreesen "jdreesen (1 commits)")[![matyo91](https://avatars.githubusercontent.com/u/1254025?v=4)](https://github.com/matyo91 "matyo91 (1 commits)")[![pgrimaud](https://avatars.githubusercontent.com/u/1866496?v=4)](https://github.com/pgrimaud "pgrimaud (1 commits)")[![xabbuh](https://avatars.githubusercontent.com/u/1957048?v=4)](https://github.com/xabbuh "xabbuh (1 commits)")

---

Tags

circuit-breakerlibraryphp74php8qualityresiliency

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/love-oss-resiliency/health.svg)

```
[![Health](https://phpackages.com/badges/love-oss-resiliency/health.svg)](https://phpackages.com/packages/love-oss-resiliency)
```

###  Alternatives

[illuminate/contracts

The Illuminate Contracts package.

705122.9M10.1k](/packages/illuminate-contracts)[phpro/soap-client

A general purpose SoapClient library

8885.6M46](/packages/phpro-soap-client)[phiki/phiki

Syntax highlighting using TextMate grammars in PHP.

3573.0M23](/packages/phiki-phiki)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

374468.4k51](/packages/flow-php-etl)[gehrisandro/tailwind-merge-php

TailwindMerge for PHP merges multiple Tailwind CSS classes by automatically resolving conflicts between them

1391.5M9](/packages/gehrisandro-tailwind-merge-php)

PHPackages © 2026

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