Download the PHP package ahmednour/circuit-breaker without Composer

On this page you can find all versions of the php package ahmednour/circuit-breaker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package circuit-breaker

Distributed Circuit Breaker for PHP & Laravel

Tests Latest Version

A production-ready, high-performance distributed Circuit Breaker package for PHP 8.2+ and Laravel. Built with clean architecture principles to protect your applications from cascading failures when third-party APIs (SMS gateways, payment processors, CRMs, email providers, etc.) become degraded or unavailable.


Key Features


Architecture & State Machine


The Four Distinct Failure Types

A resilient circuit breaker must distinguish between four completely different failure scenarios:

Failure Type Example Behavior
1. Provider Failure Twilio returns 503 Service Unavailable or cURL timeout Increment failure count; trip to OPEN if threshold is reached. Re-throws provider exception.
2. Circuit Open Provider is down and recovery timeout has not passed Fails fast immediately by throwing CircuitOpenException without touching the provider.
3. Circuit Busy Another worker is currently executing a probe in HALF_OPEN Throws CircuitBusyException to avoid concurrent probes against an unhealthy dependency.
4. Infrastructure Failure Redis server down, connection timeout, network partition Caught by CircuitBreaker and delegated to the configured policy (fail_open, fail_closed, or fallback).

Installation

Laravel Service Provider

If package auto-discovery is enabled, CircuitBreakerServiceProvider is loaded automatically. Otherwise, add it to your config/app.php providers array:

Publish the configuration file:


Configuration

The published config file is located at config/circuit-breaker.php:


Usage Examples

1. Basic Execution (Controllers / Services)

Wrap any external service call in the execute method:


2. Laravel Queues & Horizon Integration

Handle circuit open or busy states cleanly in queue jobs with automatic delay releases:


Infrastructure Failure Strategies

If the Circuit Breaker's own storage (e.g. Redis) is down, the package uses the configured infrastructure_failure.strategy:

1. Fail Open (fail_open — Default)

Executes the protected callback anyway. Ideal when service availability is prioritized over protection to prevent a Redis outage from taking down your entire application.

2. Fail Closed (fail_closed)

Rejects the operation and throws CircuitInfrastructureException. Ideal for high-risk operations (e.g. payments, money transfers, hard rate-limited APIs) where executing without safety guarantees is dangerous.

3. Fallback (fallback)

Delegates to an implementation of InfrastructureFallback (e.g. database-backed store or in-memory fallback).

Configure in config/circuit-breaker.php:


HTTP Failure Classification

The default HttpFailureClassifier intelligently distinguishes real provider outages from normal client errors:


Testing

Run the test suite using PHPUnit:

To run with sail or Docker:

Standalone In-Memory Testing

Domain logic and state machines are fully decoupled and can be tested without Redis using the provided test doubles in Tests\Support:


License

This package is open-sourced software licensed under the MIT license.


All versions of circuit-breaker with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-redis Version *
illuminate/contracts Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0 || ^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ahmednour/circuit-breaker contains the following files

Loading the files please wait ...