Download the PHP package francescomalatesta/laravel-circuit-breaker without Composer

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

Laravel Circuit Breaker

An implementation of the Circuit Breaker pattern for Laravel Framework 5.6.

Latest Version on Packagist Build Status Quality Score StyleCI

If you need an easy to use implementation of the circuit breaker pattern for your Laravel application, you're in the right place.

Note: this package is compatible with Laravel 5.6. Other/previous versions are not tested yet.

Install

You can use Composer to install the package for your project.

Don't worry about service providers and façades: Laravel can auto discover the package without doing nothing!

Just remember to publish the config file with

Usage

You will always use a single class (CircuitBreaker façade or CircuitBreakerManager class if you want to inject it) to work with this package.

Here's the methods reference:

isAvailable(string $identifier) : bool

Returns true if the $identifier service is currently available. Returns false otherwise.

Note: you can use whatever you want as identifier. I like to use the MyClass::class name when possible.

reportFailure(string $identifier) : void

Reports a failed attempt for the $identifier service. Take a look at the Configuration section below to know how attempts and failure times are managed.

reportSuccess(string $identifier) : void

Reports a successful attempt for the $identifier service. You can use it to mark a service as available and remove the "failed" status from it.

Configuration

Defaults

By editing the config/circuit_breaker.php config file contents you will able to tweak the circuit breaker in a way that is more suitable for your needs.

You have three values under the default item:

For a better understanding: by default, 3 failed attempts in 1 minute will result in a "failed" service for 5 minutes.

Service Map

Tweaking the config file is cool, but what if I need to have specific ttl and attempts count for a specific service? No problem: the services option is here to help.

As you can see in the config/circuit_breaker.php config file, you also have a services item. You can specify settings for a single service here. Here's an example:

Then, when you will call CircuitBreaker::reportFailure('my_special_service_identifier'), the circuit breaker will recognize the "special" service and use specific configuration settings, TTLs and attempts count.

Protip: you can also overwrite a single settings for a service in the service array. The others are going to be merged with the defaults.

Usage Example

Let's assume we have a payments gateway integration for our application. We will call this class PaymentsGateway.

Now, let's also assume this is a third party service: sometimes it could be down for a while. However, we don't want to stop our users from buying something, so if the PaymentsGateway service is not available we want to redirect orders to a fallback service named DelayedPaymentsGateway that will simply "queue" delayed orders to process them in the future.

Let's stub this process in the following BuyArticleOperation class.

That's great! Now we are 100% sure that our payments are going to be processed. Sometimes that's not enough.

You know, maybe the PaymentsGateway takes at least 5 seconds for a single attempt, and your application receives hundreds of orders every minute. Is it really helpful to repeatedly call the PaymentsGateway even if we "know" it's not working after the first attempt?

Well, this is how you can write your code with this circuit breaker.

Let's assume we are processing 100 orders (on different processes) in 10 seconds.

Cool, huh? :)

Testing

You can easily execute tests with

Coming Soon

Contributing

Please see CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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


All versions of laravel-circuit-breaker with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1
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 francescomalatesta/laravel-circuit-breaker contains the following files

Loading the files please wait ....