PHPackages                             postcon/resilience - 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. postcon/resilience

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

postcon/resilience
==================

Library of resilience helpers

v1.0.3(4y ago)05961MITPHPPHP &gt;=7.1CI failing

Since Nov 1Pushed 4y ago4 watchersCompare

[ Source](https://github.com/Postcon/resilience)[ Packagist](https://packagist.org/packages/postcon/resilience)[ RSS](/packages/postcon-resilience/feed)WikiDiscussions master Synced 3d ago

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

Resilience library
==================

[](#resilience-library)

[![Build Status](https://camo.githubusercontent.com/49bc973d09c9722452c98549bea94d6d62f0dfbb23e0740e35d0e60ddd5c695c/68747470733a2f2f6170692e7472617669732d63692e6f72672f506f7374636f6e2f726573696c69656e63652e737667)](https://travis-ci.org/Postcon/resilience)

A collection of reusable resilience pattern implementations. Currently implemented:

- [circuit breaker](https://martinfowler.com/bliki/CircuitBreaker.html)

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

[](#installation)

Using [composer](https://getcomposer.org/download/):

```
composer require postcon/resilience

```

Simple usage
------------

[](#simple-usage)

```
$redis = new \Redis();

$circuitBreaker = new \Postcon\Resilience\RedisCircuitBreaker($redis, 'system', 120, 3);
$circuitBreaker->reportSuccess();

$circuitBreaker->isAvailable(); // should be true
$circuitBreaker->reportFailure();
$circuitBreaker->isAvailable(); // ... still true
$circuitBreaker->reportFailure();
$circuitBreaker->isAvailable(); // ... still true
$circuitBreaker->reportFailure();
$circuitBreaker->isAvailable(); // ... now it is false

$circuitBreaker->check(); // throws CircuitBreakerTripped exception, if 'system' is not available.
```

State transitions
-----------------

[](#state-transitions)

The circuit breaker can be on one of three states: CLOSED (system is available), HALF OPEN (system is still available) and OPEN (system is not available).

The *normal* state of the circuit breaker is CLOSED; i.e. the system is working correctly. If a failure is reported, the state changes to HALF OPEN. If either a success is reported, or a defined time exceeds (*lifetime*), the state becomes CLOSED again. If failure is reported repeatedly (*maxErrors*), the state changes from HALF OPEN to OPEN (*the circuit breaker is tripped*).

The OPEN state changes back to CLOSED, after exceeding a defined time. Depending on the usage of this circuit breaker implementation, a reported success could change the OPEN state to be CLOSED as well.

```
 --------------------------      ::reportSuccess()        ---------------------------
|          CLOSED          | baseClient     = $baseClient;
        $this->circuitBreaker = $circuitBreaker;
    }

    /**
     * @inheritdoc
     *
     * @throws CircuitBreakerTripped
     */
    public function send(RequestInterface $request, array $options = [])
    {
        return $this->check(function () use ($request, $options) {
            $this->baseClient->send($request, $options);
        });
    }

    // ...

    /**
     * @throws GuzzleException
     * @throws CircuitBreakerTripped
     */
    private function check(callable $function)
    {
        $this->circuitBreaker->check();

        try {
            $result = $function();

            $this->circuitBreaker->reportSuccess();

            return $result;
        } catch (ConnectException $e) {
            $this->circuitBreaker->reportFailure();
            throw $e;
        } catch (ServerException $e) {
            $this->circuitBreaker->reportFailure();
            throw $e;
        } catch (ClientException $e) {
            $this->circuitBreaker->reportSuccess();
            throw $e;
        }
    }
}
```

Implementation details
----------------------

[](#implementation-details)

Currently, there is a [redis](https://redis.io/) [implementation](lib/RedisCircuitBreaker.php) of the circuit breaker pattern. An instance of a circuit breaker is persisted as the respective failure counter, where the redis key is the circuit breaker name.

To implement the lifetime feature (automatic state transition to CLOSED after some time), the redis [EXPIRE command](https://redis.io/commands/expire) is used.

License
-------

[](#license)

All contents of this package are licensed under the [MIT license](LICENSE).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

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 ~214 days

Total

4

Last Release

1745d ago

PHP version history (2 changes)v1.0.0PHP ^7.1

v1.0.3PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d3765b40a043c8c7c8ead0ae3cb9691ab6c053d272ec9db1d9bcec0218fb69a?d=identicon)[DrSchimke](/maintainers/DrSchimke)

![](https://www.gravatar.com/avatar/43a51254a0d2da97e28dd6790c3b939deea824cc42412b9d9a289200626d406a?d=identicon)[puhbooh](/maintainers/puhbooh)

---

Top Contributors

[![DrSchimke](https://avatars.githubusercontent.com/u/3299009?v=4)](https://github.com/DrSchimke "DrSchimke (16 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/postcon-resilience/health.svg)

```
[![Health](https://phpackages.com/badges/postcon-resilience/health.svg)](https://phpackages.com/packages/postcon-resilience)
```

###  Alternatives

[grimmlink/bootstrap-filestyle

jQuery customization of input html file for Bootstrap Twitter http://markusslima.github.io/bootstrap-filestyle/

71510.6k](/packages/grimmlink-bootstrap-filestyle)[xobotyi/basen

Text and integers encoding utilities for PHP with no extensions dependencies. Base32, Base58, Base64 and much more!

1219.6k](/packages/xobotyi-basen)

PHPackages © 2026

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