PHP code example of damianopetrungaro / circuit-breaker
1. Go to this page and download the library: Download damianopetrungaro/circuit-breaker library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
damianopetrungaro / circuit-breaker example snippets
use DamianoPetrungaro\CircuitBreaker\DefaultCircuitBreaker;
use DamianoPetrungaro\CircuitBreaker\Middleware\Base;
use DamianoPetrungaro\CircuitBreaker\Middleware\Retries;
use DamianoPetrungaro\CircuitBreaker\State\DetermineState;
use DamianoPetrungaro\CircuitBreaker\State\Persistence\InMemory;
$determineState = new DetermineState();
$resetTimeout = new DateInterval('PT10S');
$persistence = new InMemory($determineState,$maxFailure = 5,$resetTimeout);
$circuitBreaker = new DefaultCircuitBreaker($persistence, new Retries($persistence, new Base()));
$circuitBreaker->execute(static function (): string {
// Retrieve the username from the db...
// Log possible failure...
return 'username';
});