Download the PHP package algoyounes/circuit-breaker without Composer

On this page you can find all versions of the php package algoyounes/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

Build Status Total Downloads Latest Stable Version License

Circuit Breaker is a Laravel package that provides a simple and efficient way to manage service calls and prevent cascading failures. It lets you define custom callbacks for key circuit states and run operations with circuit breaker logic.

The following diagram illustrates how the Circuit Breaker Pattern works:

For more info, check the official pattern doc here.

Table of Contents

Prerequisites

This package requires:

Installation

You can install the package via Composer:

You can publish the configuration file using the following command:

Usage

You can manage specific services with granular control using the forService(...) method. the service-name parameter is a unique identifier key for your service, ensuring its circuit breaker configuration is isolated from other services.

[!TIP] Use the unique service-name key across your application to consistently reference the same circuit configuration (e.g., 'payment-service', ...)

Custom Callbacks

You can define callbacks for key circuit states:

Callback Description Parameters Received
onOpen Triggered when the circuit goes into OPEN, blocking calls to prevent further failures CircuitTransition
onHalfOpen The circuit enters HALF-OPEN to test stability, letting one request through CircuitTransition
onClose The circuit returns to CLOSED, allowing all requests without restrictions CircuitTransition
onSuccess Fires when a request succeeds, indicating system availability CircuitResult, CircuitTransition
onFailure Triggered when a request fails, potentially opening the circuit CircuitResult, CircuitTransition
onSteadyState Indicates the circuit is stable, with no need for changes CircuitTransition

Example of defining callbacks:

Running an Operation

To run an operation and manage its state through the circuit breaker, use the run method:

This will execute the provided closure, applying the circuit breaker logic (e.g., open, half-open, closed states) around the service call.

[!NOTE] If you prefer a more direct approach, you can create a CircuitBuilder instance:

Simplified Operation

For a simplified approach, use the run method directly from CircuitManager:

Guzzle Middleware Integration

The package provides a Guzzle middleware to automatically manage circuit breaker logic for HTTP requests.

To enable the middleware, add the following to your Guzzle client configuration:

Laravel Http Facade Integration

The package integrates with Laravel's built-in Http facade out of the box:

This automatically applies the circuit breaker middleware to the request using payment-service as the circuit key. You can chain it with any Http method:

When the circuit is open, a RejectedException is thrown:

How It Works

State Transitions

The circuit breaker operates in three states:

Half-Open State Behavior

When a circuit transitions from OPEN to HALF-OPEN, this package uses a single-probe approach — only one request is allowed to test the recovering service at a time. All other concurrent requests are rejected immediately until the probe completes.

What your code receives when a request is rejected:

Configuration

After publishing the config file, you can adjust these settings in config/circuit-breaker.php:

Option Default Description
enabled true Enable or disable the circuit breaker globally
defaults.failure_threshold 5 Number of failures before the circuit opens
defaults.cooldown_period 60 Seconds to wait before transitioning from OPEN to HALF-OPEN
defaults.success_threshold 1 Successful probes needed in HALF-OPEN to close the circuit
cache.ttl 86400 Cache entry lifetime in seconds
cache.prefix circuit-breaker Prefix for cache keys
cache.store default Laravel cache store to use

You can also override settings per service:

Contributing

Thank you for considering contributing to the Circuit Breaker package! Please check the CONTRIBUTING file for more details.

License

The Circuit Breaker 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
illuminate/support Version ^11.0|^12.0
illuminate/contracts Version ^11.0|^12.0
illuminate/cache Version ^11.0|^12.0
illuminate/http Version ^11.0|^12.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 algoyounes/circuit-breaker contains the following files

Loading the files please wait ...