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

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

syastrebov/circuit-breaker-bundle
=================================

Symfony bundle for circuit breaker wrapper.

v0.1(3mo ago)016MITPHPPHP ^8.3CI passing

Since Feb 6Pushed 3mo ago1 watchersCompare

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

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

PHP Circuit Breaker implementation for microservices and API calls.

A Symfony bundle for the  library.

Install
-------

[](#install)

If you're using flex add to your composer.json

```
{
  ...

  "extra": {
    "symfony": {
      "endpoint": [
        "https://api.github.com/repos/syastrebov/recipies/contents/index.json",
        "flex://defaults"
      ]
    }
  }
}
```

Install via composer

```
composer require syastrebov/circuit-breaker-bundle
```

Config
------

[](#config)

### Supported Providers

[](#supported-providers)

#### Database

[](#database)

`config/packages/doctrine.yaml`

```
doctrine:
  dbal:
    default_connection: default
    connections:
      default:
        driver: pdo_sqlite
        path: ':memory:'
      secondary:
        driver: pdo_mysql
        host: mysql
        user: user
        password: password
        dbname: database
```

`config/packages/circuit_breaker.yaml`

```
circuit_breaker:
  driver: database
  connections:
    database:
      connection: secondary
```

#### Memcached

[](#memcached)

`config/packages/circuit_breaker.yaml`

```
circuit_breaker:
  driver: memcached
  connections:
    memcached:
      servers:
        # Uses default port
        - host: memcached-1
        # Explicitly define port
        - host: memcached-2
          port: 11211
```

#### Redis

[](#redis)

Uses `redis` extension or `predis` as fallback.

`config/packages/circuit_breaker.yaml`

```
circuit_breaker:
  driver: redis
  connections:
    redis:
      host: redis
      port: 6379
      username: username
      password: password
```

#### Redis Cluster

[](#redis-cluster)

Uses `redis` extension or `predis` as fallback.

`config/packages/circuit_breaker.yaml`

```
circuit_breaker:
  driver: redis
  connections:
    redis:
      nodes:
        # Uses default port
        - host: redis-node-1
        - host: redis-node-2
        # Explicitly define port
        - host: redis-node-3
          port: 6379
      password: password
```

#### Predis

[](#predis)

To force Predis usage despite the redis extension being installed:

`config/packages/circuit_breaker.yaml`

```
circuit_breaker:
  driver: predis
```

#### Memory

[](#memory)

config/packages/circuit\_breaker.yaml

```
circuit_breaker:
  driver: memory
```

### Multiple Instances

[](#multiple-instances)

`config/packages/circuit_breaker.yaml`

```
circuit_breaker:
  configurations:
    default:
      retries: 3
      closed_threshold: 3
      half_open_threshold: 3
      retry_interval: 1000
      open_timeout: 60
      fallback_or_null: false
    api:
      retries: 2
      closed_threshold: 5
      half_open_threshold: 10
      retry_interval: 2000
      open_timeout: 120
      fallback_or_null: true
```

```
use CircuitBreaker\Contracts\CircuitBreakerInterface;

public function requestDefault(
    #[Autowire(service: 'circuit_breaker.default')]
    CircuitBreakerInterface $circuit
): string {
    // handle request
}

public function requestApi(
    #[Autowire(service: 'circuit_breaker.api')]
    CircuitBreakerInterface $circuit
): string {
    // handle request
}
```

### Logger

[](#logger)

```
circuit_breaker:
  logger: monolog.logger.circuit_breaker
```

Usage
-----

[](#usage)

### Simple example:

[](#simple-example)

```
use CircuitBreaker\Contracts\CircuitBreakerInterface;

public function request(CircuitBreakerInterface $circuit): string
{
    try {
        return $circuit->run('test', function () {
            return '{"response": "data"}';
        });
    } catch (UnableToProcessException $e) {
        // handle exception
    }
}
```

### Use custom config:

[](#use-custom-config)

```
use CircuitBreaker\Contracts\CircuitBreakerInterface;

public function request(
    #[Autowire(service: 'circuit_breaker.api')]
    CircuitBreakerInterface $circuit
): string {
    try {
        return $circuit->run('test', function () {
            return '{"response": "data"}';
        });
    } catch (UnableToProcessException $e) {
        // handle exception
    }
}
```

### Stub response:

[](#stub-response)

```
use CircuitBreaker\Contracts\CircuitBreakerInterface;

public function request(
    #[Autowire(service: 'circuit_breaker.api')]
    CircuitBreakerInterface $circuit
): string {
    return $circuit->run(
        '{endpoint}',
        static function () {
            return (string) (new Client)->get('https://domain/api/{endpoint}')->getBody();
        },
        static function () {
            return json_encode([
                'data' => [
                    'key' => 'default value',
                ],
            ]);
        }
    );
}
```

### Cacheable response:

[](#cacheable-response)

Configure a cache pool to be able to use cacheable circuit breaker.

config/packages/framework.yaml

```
framework:
  cache:
    pools:
      circuit_breaker.pool:
        adapter: cache.adapter.filesystem
```

config/packages/circuit\_breaker.yaml

```
circuit_breaker:
  provider: memory
  cache_pool: circuit_breaker.pool

  configurations:
    api:
      retries: 2
      closed_threshold: 5
      half_open_threshold: 10
      retry_interval: 3000
      open_timeout: 120
      fallback_or_null: true
```

Use `.cacheable` suffix to use `CacheableCircuitBreaker`.

```
use CircuitBreaker\Contracts\CircuitBreakerInterface;

public function request(
    #[Autowire(service: 'circuit_breaker.api.cacheable')]
    CircuitBreakerInterface $circuit
): string {
    return $circuit->run('{endpoint}', static function () {
        return (string) (new Client)->get('https://domain/api/{endpoint}')->getBody();
    });
}
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance82

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

95d ago

### Community

Maintainers

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

---

Top Contributors

[![syastrebov](https://avatars.githubusercontent.com/u/1681915?v=4)](https://github.com/syastrebov "syastrebov (18 commits)")

###  Code Quality

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/ux-chartjs

Chart.js integration for Symfony

1003.2M18](/packages/symfony-ux-chartjs)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[symfony/ux-cropperjs

Cropper.js integration for Symfony

19280.3k3](/packages/symfony-ux-cropperjs)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[pentiminax/ux-datatables

DataTables.net integration for Symfony

605.6k](/packages/pentiminax-ux-datatables)

PHPackages © 2026

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