PHPackages                             flavioheleno/interrupt - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. flavioheleno/interrupt

ActiveLibrary[HTTP &amp; Networking](/categories/http)

flavioheleno/interrupt
======================

PSR-18 compliant Circuit Breaker wrapper

1147PHPCI failing

Since Mar 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/flavioheleno/interrupt)[ Packagist](https://packagist.org/packages/flavioheleno/interrupt)[ RSS](/packages/flavioheleno-interrupt/feed)WikiDiscussions main Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Interrupt - Uninterrupted Reliability for HTTP Requests
=======================================================

[](#interrupt---uninterrupted-reliability-for-http-requests)

This library implements a PSR-18 compliant Circuit Breaker wrapper that can be used to ensure service stability and prevent overload or degradation in remote service calls.

Acknowledgement
---------------

[](#acknowledgement)

This library is heavily inspired by:

- [ackintosh/ganesha](https://github.com/ackintosh/ganesha)
- [PrestaShop/circuit-breaker](https://github.com/PrestaShop/circuit-breaker)

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

[](#installation)

To use Interim, install it using composer:

```
composer require flavioheleno/interrupt
```

Usage
-----

[](#usage)

### As a PSR-18 HTTP Client Wrapper

[](#as-a-psr-18-http-client-wrapper)

```
// any PSR-18 compliant HTTP Client implementation
// $httpClient = new ...

// resolves the service name to its scheme + host + port
// eg. https://api.example.org/v1 -> https://api.example.org
// eg. https://api.example.org:5000/v1 -> https://api.example.org:5000
// can be replaced by StaticNameResolver
$serviceNameResolver = Interrupt\ServiceNameResolvers\UriBasedResolver();

// any PSR-6 compliant Cache Item Pool implementation
// $cacheItemPool = new ...

// any PSR-20 compliant Clock implementation
// $clock = new ...

// can be replaced by FixedTimeWindowBasedRecordStrategy
$recordStrategy = new Interrupt\RecordStrategies\SlidingTimeWindowBasedRecordStrategy(
  $clock
);

// can be replaced by CountBasedCircuitBreaker
$circuitBreaker = new Interrupt\CircuitBreakers\RateBasedCircuitBreaker(
  $clock,
  $cacheItemPool,
  $recordStrategy
);

$failureDetector = new Interrupt\FailureDetectors\HttpStatusBasedFailureDetector();

$client = new Psr18Wrapper(
  $httpClient,
  $serviceNameResolver,
  $circuitBreaker,
  $failureDetector
);

// when the called service is unavailable, $client will throw an
// Interrupt\Exceptions\ServiceUnavailableException exception.
```

### As a Guzzle Middleware

[](#as-a-guzzle-middleware)

```
$middleware = new GuzzleMiddleware(
  $serviceNameResolver,
  $circuitBreaker,
  $failureDetector
);

$handlerStack = \GuzzleHttp\HandlerStack::create();
$handlerStack->push($middleware);

$client = new GuzzleHttp\Client(['handler' => $handlerStack]);

// when the called service is unavailable, $client will throw an
// Interrupt\Exceptions\ServiceUnavailableException exception.
```

Components
----------

[](#components)

Interrupt is built around the concept of components to allow easy integration with different environments or frameworks, making it a flexible and customizable library.

### Service Name Resolver

[](#service-name-resolver)

To keep track of services accessed by the wrapped client, Interrupt uses the concept of [Service Name Resolvers](src/Contracts/ServiceNameResolverInterface.php), that generates consistent service names based on request attributes.

Interrupt is distributed with:

- [UriBasedResolver](src/ServiceNameResolvers/UriBasedResolver.php), a resolver implementation that generates service names from the request URI components
- [StaticNameResolver](src/ServiceNameResolvers/StaticNameResolver.php), a resolver implementation that always return a constant service name

### Record Strategy

[](#record-strategy)

The [Record Strategy](src/Contracts/RecordStrategyInterface.php) determines how Interrupt keeps track of failure events during a period of time.

A [FixedTimeWindowBasedRecordStrategy](src/RecordStrategies/FixedTimeWindowBasedRecordStrategy.php) that uses a predefined time interval to register failure records within its duration. Once the interval is over, the recorded failures are cleaned up and a new fixed interval starts.

A [SlidingTimeWindowBasedRecordStrategy](src/RecordStrategies/SlidingTimeWindowBasedRecordStrategy.php) that uses a moving or shifting time interval to register failure records. Instead of fixed intervals, the time window slides (or moves along) with the failure stream.

The *Sliding Time Window* approach allows for continuous analysis of the most recent data while still considering a specific timeframe.

Note

Both strategies require a [PSR-20](https://www.php-fig.org/psr/psr-20/) compatible Clock implementation.

### Failure Detector

[](#failure-detector)

Failure can be subjective to context so Interrupt relies on [Failure Detector](src/Contracts/FailureDetectorInterface.php)to detect context-dependant failures.

Embedded in [Psr18Wrapper](src/Psr18Wrapper.php) is the failure detection for network issues, timeouts and any other thrown exception that extends `Psr\Http\Client\ClientExceptionInterface`.

In addition to that, the [HttpStatusBasedFailureDetector](src/FailureDetectors/HttpStatusBasedFailureDetector.php)interprets the HTTP Status Code as signal of failure.

### Circuit Breakers

[](#circuit-breakers)

Interrupt comes with two [Circuit Breakers](src/Contracts/CircuitBreakerInterface.php) implementations:

A [CountBasedCircuitBreaker](src/CircuitBreakers/CountBasedCircuitBreaker.php) that monitors the number of failures recorded and automatically interrupts the flow of requests if the threshold is exceeded.

A [RateBasedCircuitBreaker](src/CircuitBreakers/RateBasedCircuitBreaker.php) that monitors the rate or frequency of failures recorded and automatically interrupts the flow of requests if the error rate surpasses a predefined threshold.

Note

Both circuit breakers require a [PSR-6](https://www.php-fig.org/psr/psr-6/) compatible Cache implementation.

License
-------

[](#license)

This library is licensed under the [MIT License](LICENSE).

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity20

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/471860?v=4)[Flávio Heleno](/maintainers/flavioheleno)[@flavioheleno](https://github.com/flavioheleno)

---

Top Contributors

[![flavioheleno](https://avatars.githubusercontent.com/u/471860?v=4)](https://github.com/flavioheleno "flavioheleno (21 commits)")

---

Tags

circuit-breakercircuit-breaker-patternfailure-handlingguzzle-middlewarehttp-clientphppsr-18

### Embed Badge

![Health badge](/badges/flavioheleno-interrupt/health.svg)

```
[![Health](https://phpackages.com/badges/flavioheleno-interrupt/health.svg)](https://phpackages.com/packages/flavioheleno-interrupt)
```

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25026.8M85](/packages/php-http-cache-plugin)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

85997.3k131](/packages/httpsoft-http-message)[thesis/nats

Async (fiber based) client for Nats.

758.3k](/packages/thesis-nats)

PHPackages © 2026

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