PHPackages                             mt-olympus/cerberus - 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. mt-olympus/cerberus

Abandoned → [los/cerberus](/?search=los%2Fcerberus)Library[Utility &amp; Helpers](/categories/utility)

mt-olympus/cerberus
===================

Circuit Breaker pattern implementation in PHP

1.1.0(9y ago)420.8k11MITPHPPHP ^5.6 || ^7.0

Since Nov 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mt-olympus/cerberus)[ Packagist](https://packagist.org/packages/mt-olympus/cerberus)[ Docs](https://github.com/mt-olympus/cerberus)[ RSS](/packages/mt-olympus-cerberus/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (5)Used By (1)

Cerberus
========

[](#cerberus)

[![Build Status](https://camo.githubusercontent.com/da601ad9cb34b44a23cea77e31d4246255f3bffca4a535e833774c5c0dbc4db8/68747470733a2f2f7472617669732d63692e6f72672f6d742d6f6c796d7075732f63657262657275732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mt-olympus/cerberus) [![Coverage Status](https://camo.githubusercontent.com/365f36e4e09c1073fb6727a97d2033c1cee6dbff3d86908abc32fdafd48c038a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f4c616e736f7765622f63657262657275732f62616467652e7376673f6272616e63683d6d617374657226736572766963653d676974687562)](https://coveralls.io/github/Lansoweb/cerberus?branch=master) [![Latest Stable Version](https://camo.githubusercontent.com/556f76d0a61fd94a3ef0d7f90cf6f3708a16f19c6feeb113ad96d8d93c5f8084/68747470733a2f2f706f7365722e707567782e6f72672f6d742d6f6c796d7075732f63657262657275732f762f737461626c652e737667)](https://packagist.org/packages/mt-olympus/cerberus) [![Total Downloads](https://camo.githubusercontent.com/2e3010599de85dd4f60446ab1da89f786abc9f62783dfed978c251c085a0472b/68747470733a2f2f706f7365722e707567782e6f72672f6d742d6f6c796d7075732f63657262657275732f646f776e6c6f6164732e737667)](https://packagist.org/packages/mt-olympus/cerberus) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/5a585bff80ae47f3ce88c23f4508a6d6ef4e99b2bf330a07a6fbf15882953eea/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d742d6f6c796d7075732f63657262657275732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mt-olympus/cerberus/?branch=master) [![SensioLabs Insight](https://camo.githubusercontent.com/7fbb19c60cd98231535f4f487452c18355932a05e761599694afad3fd4736fbd/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f61343032613932662d313433642d343332612d396130322d3863346165363437353263322e7376673f7374796c653d666c6174)](https://insight.sensiolabs.com/projects/a402a92f-143d-432a-9a02-8c4ae64752c2)

Introduction
------------

[](#introduction)

This is a Circuit Breaker pattern implementation in PHP.

This library helps you to handle external services timeouts and outages.

It detects service failures and adapts itself.

You can combine this library with [Metis](https://github.com/mt-olympus/metis) to have a realiable Load Balance service.

Requirements
------------

[](#requirements)

- PHP &gt;= 5.5
- [Zend Cache](https://github.com/zendframework/zend-cache)

Instalation
-----------

[](#instalation)

```
composer require mt-olympus/cerberus:~1.0

```

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

[](#configuration)

You can manually create a Cerberus instance or use a Factory

### Factory

[](#factory)

If you use a [Container Interopt](https://github.com/container-interop/container-interop) campatible project, you can define a factory:

```
'factories' => [
    Cerberus\Cerberus::class => Cerberus\Factory::class
],
```

and copy the configuration file config/cerberus.global.php.dist to your config/autoload/cerberus.global.php and change to your needs.

```
return [
    'cerberus' => [
        'max_failues' => 5,
        'timeout' => 60,
        'storage' => [
            'adapter' => [
                'name' => 'filesystem',
                'options' => [
                    'cache_dir' => 'data/cache',
                    'namespace' => 'my_project'
                ]
            ],
            'plugins' => [
                // Don't throw exceptions on cache errors
                'exception_handler' => [
                    'throw_exceptions' => false
                ]
            ]
        ]
    ]
];
```

The `maxFailure` parameter is the number of failures after which the circuit is opened and the service becomes not available.

When the `timeout` is reached, the circuit becomes half opened and one attempt is possible and the status is updated.

The storage key is a zend-cache configuration. You can check the [official documentation](https://github.com/zendframework/zend-cache).

The `namespace` key inside the storage is important. It defines de default namespace for Cerberus cache capabilities. If you choose to call Cerberus methods with service name (see Usage bellow), you can ommit this as it will be ignored.

### Manually

[](#manually)

You can create a Cerberus instance manually:

```
$storage = StorageFactory::factory($storageConfig);
$cerberus = new Cerberus($storage, 5, 60);
```

The $storageConfig is the zend-cache configuration as above.

Usage
-----

[](#usage)

The usage is simple. Each time you will access a remote resource (like an Web Service), check for its availability and report its success or failure:

```
if ($cerberus->isAvailable()) {
    try {
        $http->makeRequest();
        $cerberus->reportSuccess();
    } catch (\Exception $ex) {
        $cerberus->reportFailure();
    }
}
```

You can use Cerberus to control more than one service. In this scenario, use the methods passing a service name:

```
if ($cerberus->isAvailable('service-one')) {
    try {
        $http->makeRequest();
        $cerberus->reportSuccess('service-one');
    } catch (\Exception $ex) {
        $cerberus->reportFailure('service-one');
    }
}

if ($cerberus->isAvailable('service-two')) {
    try {
        $http->makeRequest();
        $cerberus->reportSuccess('service-two');
    } catch (\Exception $ex) {
        $cerberus->reportFailure('service-two');
    }
}
```

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 90.5% 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 ~127 days

Total

3

Last Release

3633d ago

PHP version history (3 changes)1.0.0PHP &gt;=5.5

1.0.1PHP ^5.5|^7.0

1.1.0PHP ^5.6 || ^7.0

### Community

Maintainers

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

---

Top Contributors

[![Lansoweb](https://avatars.githubusercontent.com/u/2109813?v=4)](https://github.com/Lansoweb "Lansoweb (19 commits)")[![samsonasik](https://avatars.githubusercontent.com/u/459648?v=4)](https://github.com/samsonasik "samsonasik (2 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mt-olympus-cerberus/health.svg)

```
[![Health](https://phpackages.com/badges/mt-olympus-cerberus/health.svg)](https://phpackages.com/packages/mt-olympus-cerberus)
```

###  Alternatives

[zf-commons/zfc-base

A set of genetic (abstract) classes which are commonly used across multiple modules.

1491.1M25](/packages/zf-commons-zfc-base)[bitweb/zf2-cron-module

BitWeb ZF2 module for cron.

1242.9k](/packages/bitweb-zf2-cron-module)

PHPackages © 2026

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