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

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

moontechs/circuit-breaker
=========================

An in memory (default driver) circuit breaker implementation with different strategies. No dependencies.

0.0.3(2y ago)058MITPHPPHP &gt;=8.0

Since Oct 1Pushed 2y agoCompare

[ Source](https://github.com/moontechs/circuit-breaker)[ Packagist](https://packagist.org/packages/moontechs/circuit-breaker)[ RSS](/packages/moontechs-circuit-breaker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

Circuit breaker
===============

[](#circuit-breaker)

An in-memory (default driver) circuit breaker implementation with different strategies. It is very useful if you have a long job that does a lot of HTTP requests in a loop. Check the [Example](#example) section.

No dependencies.

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

[](#installation)

`composer require moontechs/circuit-breaker`

Usage
-----

[](#usage)

### Choose a strategy

[](#choose-a-strategy)

- Counter strategy - simple failures increment. When a limit is reached `isAvailable` function returns false. Calling the `success` function will reset the counter (will set 0).
    - `limit` - the default value is 5. Use the `setLimit(int)` method to change it.

```
use Moontechs\CircuitBreaker\CircuitBreaker;
use Moontechs\CircuitBreaker\Drivers\InMemoryDriver;
use Moontechs\CircuitBreaker\Strategies\CounterStrategy;

$circuitBreaker = new CircuitBreaker(
    new CounterStrategy(
        new InMemoryDriver()
    )
);
```

- Time frame strategy - failures increment during a specified time frame. When a limit is reached during the time frame `isAvailable` function returns false. Calling the `success` function will reset the counter (will set 0).
    - `limit` - the default value is 5. Use the `setLimit(int)` method to change it.
    - `timeFrame` - the default value is 300 seconds. Use the `setTimeFrame(int)` method to change it.

```
use Moontechs\CircuitBreaker\CircuitBreaker;
use Moontechs\CircuitBreaker\Drivers\InMemoryDriver;
use Moontechs\CircuitBreaker\Strategies\TimeFrameStrategy;

$circuitBreaker = new CircuitBreaker(
    new TimeFrameStrategy(
        new InMemoryDriver()
    )
);
```

The default driver is `InMemoryDriver`. It does not share the data between processes.

### Example

[](#example)

An example of a real-world usage.

```
use Moontechs\CircuitBreaker\CircuitBreaker;
use Moontechs\CircuitBreaker\Drivers\InMemoryDriver;
use Moontechs\CircuitBreaker\Strategies\CounterStrategy;

$circuitBreaker = new CircuitBreaker(
    new CounterStrategy(
        new InMemoryDriver()
    )
);

foreach ($data as $datum) {
    try {
        exampleHttpRequest($datum);

        // This is optional. In case if you want to reset the failures counter.
        $circuitBreaker->success('example');
    } catch (\Exception $exception) {
        $circuitBreaker->failure('example');

        // The following condition could be used to throw an exception or repeat a request later.
        if (!$circuitBreaker->isAvailable('example')) {
            throw $exception;
        }

        // This is optional. In case you want to prevent another service from spamming and give it some time to recover.
        sleep($circuitBreaker->getFailuresCount() * 10);
    }
}
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Total

3

Last Release

953d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/60574a1638aef5279e9547cc7f44d28f6017ad4e056c92056c6653f42d3d034d?d=identicon)[mkoziy](/maintainers/mkoziy)

---

Top Contributors

[![mkoziy](https://avatars.githubusercontent.com/u/3823545?v=4)](https://github.com/mkoziy "mkoziy (5 commits)")

---

Tags

circuit-breakercircuit-breaker-patternphp

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[mbezhanov/faker-provider-collection

A collection of custom providers for the Faker library

2138.6M24](/packages/mbezhanov-faker-provider-collection)[internal/destroy

55870.4k7](/packages/internal-destroy)[guava/filament-clusters

Filament clusters allow you to cluster multiple fields into one visually.

15881.9k1](/packages/guava-filament-clusters)[m6web/statsd

Component easing the statsd usage

131.0M2](/packages/m6web-statsd)[astrotomic/php-conditional-proxy

This package provides a trait and class to allow calling methods based on a condition without breaking the method chain.

30155.8k5](/packages/astrotomic-php-conditional-proxy)[devtical/nova-qrcode-field

Nova QR code field

4560.6k2](/packages/devtical-nova-qrcode-field)

PHPackages © 2026

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