1. Go to this page and download the library: Download algoyounes/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/ */
$this->circuitManager->run('service-name', function () {
// Your service call here
});
// or
$this->circuitManager->run('service-name', $this->serviceName->create(...));
use AlgoYounes\CircuitBreaker\Middleware\GuzzleMiddleware;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
$stack = HandlerStack::create();
$stack->push(GuzzleMiddleware::create());
$client = new Client([
'handler' => $stack,
]);
$response = $client->get('https://api.example.com', [
'headers' => [
'X-Circuit-Key' => 'service-name',
],
]);