PHPackages                             ksaveras/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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. ksaveras/circuit-breaker

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

ksaveras/circuit-breaker
========================

Circuit Breaker library

2.1.0(2y ago)61.5k↓90%[12 PRs](https://github.com/ksaveras/circuit-breaker/pulls)2MITPHPPHP ^8.1CI passing

Since Feb 25Pushed 2w ago1 watchersCompare

[ Source](https://github.com/ksaveras/circuit-breaker)[ Packagist](https://packagist.org/packages/ksaveras/circuit-breaker)[ RSS](/packages/ksaveras-circuit-breaker/feed)WikiDiscussions main Synced yesterday

READMEChangelog (7)Dependencies (9)Versions (32)Used By (2)

Circuit Breaker
===============

[](#circuit-breaker)

More information:

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

[](#installation)

```
composer require ksaveras/circuit-breaker

```

Use cases
---------

[](#use-cases)

### Basic example

[](#basic-example)

Simple circuit check using Symfony Redis cache

```
use Ksaveras\CircuitBreaker\CircuitBreakerFactory;
use Ksaveras\CircuitBreaker\Storage\CacheStorage;
use Ksaveras\CircuitBreaker\Policy\ExponentialRetryPolicy;
use Symfony\Component\Cache\Adapter\RedisAdapter;

$redisAdapter = new RedisAdapter(
    RedisAdapter::createConnection('redis://localhost'),
    // the namespace for circuit breaker storage
    'circuit-breaker',
    // max TTL is set to 24 hours
    86400
);

$factory = new CircuitBreakerFactory(
    // max 3 failures before setting circuit breaker as open
    3,
    new CacheStorage($redisAdapter),
    // exponential retry starting with 30 seconds
    new ExponentialRetryPolicy(30),
);

$circuitBreaker = $factory->create('service-api');

if ($circuitBreaker->isAvailable()) {
    try {
        // call 3rd party service api
        $circuitBreaker->recordSuccess();
    } catch (\Exception $exception) {
        $circuitBreaker->recordFailure();
    }
}

// check if CB is closed
$circuitBreaker->isClosed();

// check if CB is half open
$circuitBreaker->isHalfOpen();

// check if CB is open
$circuitBreaker->isOpen();

// get number of failures
$circuitBreaker->getFailureCount();

// get CB remaining delay in seconds
$circuitBreaker->remainingDelay();
```

### Use callback

[](#use-callback)

```
use Ksaveras\CircuitBreaker\CircuitBreakerFactory;
use Ksaveras\CircuitBreaker\Storage\CacheStorage;
use Ksaveras\CircuitBreaker\Policy\ExponentialRetryPolicy;
use Symfony\Component\Cache\Adapter\RedisAdapter;

$redisAdapter = new RedisAdapter(
    RedisAdapter::createConnection('redis://localhost'),
    // the namespace for circuit breaker storage
    'circuit-breaker',
    // max TTL is set to 24 hours
    86400
);

$factory = new CircuitBreakerFactory(
    // max 3 failures before setting circuit breaker as open
    3,
    new CacheStorage($redisAdapter),
    // exponential retry starting with 30 seconds
    new ExponentialRetryPolicy(30),
);

$circuitBreaker = $factory->create('service-api');

try {
    $result = $circuitBreaker->call(
        function () {
            $this->callApi();
        }
    );
} catch (OpenCircuitException $exception) {
    // Open circuit
} catch (\Exception $exception) {
    // 3rd party exception
}
```

### Use Retry-After response header policy

[](#use-retry-after-response-header-policy)

```
use Ksaveras\CircuitBreaker\CircuitBreakerFactory;
use Ksaveras\CircuitBreaker\HeaderPolicy\PolicyChain;
use Ksaveras\CircuitBreaker\HeaderPolicy\RateLimitPolicy;
use Ksaveras\CircuitBreaker\HeaderPolicy\RetryAfterPolicy;
use Ksaveras\CircuitBreaker\Policy\ExponentialRetryPolicy;
use Ksaveras\CircuitBreaker\Storage\CacheStorage;
use Symfony\Component\Cache\Adapter\RedisAdapter;

$redisAdapter = new RedisAdapter(
    RedisAdapter::createConnection('redis://localhost'),
    // the namespace for circuit breaker storage
    'circuit-breaker',
    // max TTL is set to 24 hours
    86400
);

$factory = new CircuitBreakerFactory(
    // max 3 failures before setting circuit breaker as open
    3,
    new CacheStorage($redisAdapter),
    // exponential retry starting with 30 seconds
    new ExponentialRetryPolicy(30),
    // check for Retry-After or X-Rate-Limit-Reset headers
    new PolicyChain(
        new RetryAfterPolicy(),
        new RateLimitPolicy(),
    ),
);

$circuitBreaker = $factory->create('service-api');

// \Psr\Http\Message\ResponseInterface
$response = $apiClient->call();

// Too Many Requests
if ($response->getStatusCode() === 429) {
    $circuitBreaker->recordRequestFailure($response);
}
```

Tests
-----

[](#tests)

```
composer test

```

Code Quality
------------

[](#code-quality)

```
composer static-analysis

```

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance63

Regular maintenance activity

Popularity22

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 56.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 ~131 days

Recently: every ~193 days

Total

13

Last Release

743d ago

Major Versions

v0.3.2 → v1.0.02022-05-04

1.1.x-dev → 2.0.02023-06-24

PHP version history (3 changes)v0.1.0PHP ^7.2.5

v1.0.0PHP ^7.4|^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/485111?v=4)[Ksaveras Sakys](/maintainers/ksaveras)[@ksaveras](https://github.com/ksaveras)

---

Top Contributors

[![ksaveras](https://avatars.githubusercontent.com/u/485111?v=4)](https://github.com/ksaveras "ksaveras (133 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (95 commits)")[![release-automaton[bot]](https://avatars.githubusercontent.com/in/341347?v=4)](https://github.com/release-automaton[bot] "release-automaton[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

circuit-breakercircuit-breaker-patternerror-handlingfault-tolerancemicroservicespackagephperror handlingmicroservicescircuit breakerfault tolerancegraceful

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M738](/packages/sylius-sylius)[symfony/security-bundle

Provides a tight integration of the Security component into the Symfony full-stack framework

2.5k185.6M2.4k](/packages/symfony-security-bundle)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[ackintosh/ganesha

PHP implementation of Circuit Breaker pattern

6684.3M15](/packages/ackintosh-ganesha)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)

PHPackages © 2026

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