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

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

yaknet/circuit-breaker
======================

A robust and resilient Circuit Breaker implementation for PHP applications.

v1.1.1(1w ago)04—0%MITPHPPHP &gt;=8.1

Since May 13Pushed 1w agoCompare

[ Source](https://github.com/y-packages/php-circuit-breaker)[ Packagist](https://packagist.org/packages/yaknet/circuit-breaker)[ Docs](https://github.com/yaknet/circuit-breaker)[ RSS](/packages/yaknet-circuit-breaker/feed)WikiDiscussions main Synced 1w ago

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

YakNet \\ Circuit Breaker
=========================

[](#yaknet--circuit-breaker)

[![PHP Version](https://camo.githubusercontent.com/4453c2f41befe802c9e573c2923911bbb3d82c558d661d4148d6381488f0d573/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393262662e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A robust, resilient, and lightweight Circuit Breaker implementation for modern PHP applications. Prevent cascading failures and make your system more reliable when interacting with external APIs or microservices.

🚀 Features
----------

[](#-features)

- **Modern PHP 8.1+**: Leverages Enums, Readonly properties, and strictly typed logic.
- **Fail-Fast Strategy**: Immediately blocks requests to failing services to save resources and allow recovery.
- **Three-State Management**: Full support for `CLOSED`, `OPEN`, and `HALF_OPEN` states.
- **Storage Agnostic**: Comes with `FileStorage` out of the box, with an interface to easily add Redis or Memcached.
- **Developer Friendly**: Simple API and zero-dependency core.

📦 Installation
--------------

[](#-installation)

```
composer require yaknet/circuit-breaker
```

🛠 Usage
-------

[](#-usage)

### Basic Example

[](#basic-example)

```
use YakNet\CircuitBreaker\CircuitBreaker;
use YakNet\CircuitBreaker\Storage\FileStorage;
use YakNet\CircuitBreaker\Settings;

// 1. Initialize Storage
$storage = new FileStorage(__DIR__ . '/cache');

// 2. Configure Settings (Optional)
$settings = new Settings(
    failureThreshold: 5,
    retryTimeout: 60
);

// 3. Create the Breaker
$breaker = new CircuitBreaker('GeminiAPI', $storage, $settings);

// 4. Run your risky operation
try {
    $result = $breaker->run(function() {
        // Your logic here (e.g. API call)
        return $api->fetchData();
    });
} catch (\YakNet\CircuitBreaker\Exception\CircuitOpenException $e) {
    // Service is currently down, handle gracefully
    echo "Service unavailable. Try again in " . $e->getMessage();
}
```

🔧 Core States
-------------

[](#-core-states)

StateDescription**CLOSED**Normal operation. Requests flow through to the service.**OPEN**Failure threshold reached. Requests fail immediately without hitting the service.**HALF\_OPEN**Trial period. A limited number of requests are allowed to check if the service recovered.🧪 Testing
---------

[](#-testing)

```
composer test
```

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

---

Developed with ❤️ by [YakNet](https://yak.net.tr)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance98

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

Total

3

Last Release

9d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/236650944?v=4)[yakistir98](/maintainers/yakistir98)[@yakistir98](https://github.com/yakistir98)

---

Top Contributors

[![yaknetbilisim](https://avatars.githubusercontent.com/u/242705004?v=4)](https://github.com/yaknetbilisim "yaknetbilisim (3 commits)")

---

Tags

circuit breakerfault toleranceresilienceyaknetfail-fast

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[ejsmont-artur/php-circuit-breaker

PHP Circuit Breaker component

169993.3k4](/packages/ejsmont-artur-php-circuit-breaker)[gabrielanhaia/laravel-circuit-breaker

Laravel integration for PHP Circuit Breaker — multiple storage drivers, middleware, Artisan commands, and event system

491.6k](/packages/gabrielanhaia-laravel-circuit-breaker)[francescomalatesta/laravel-circuit-breaker

A circuit breaker pattern implementation for the Laravel framework

2919.2k2](/packages/francescomalatesta-laravel-circuit-breaker)

PHPackages © 2026

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