PHP code example of aguimaraes / circuit-breaker
1. Go to this page and download the library: Download aguimaraes/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/ */
aguimaraes / circuit-breaker example snippets
$cb = new Aguimaraes\CircuitBreaker(
new Aguimaraes\Adapter\ACPu()
);
// number of errors necessary to open the circuit
$cb->setThreshold('my-service', 10);
// wait x seconds to check if service is back
$cb->setTimeout('my-service', 60);
$response = null;
if ($cb->isAvailable('my-service')) {
try {
$response = $service->makeCall();
$cb->reportSuccess('my-service');
} catch (ServiceException $e) {
$cb->reportFailure('my-service');
} catch (NonServiceRelatedException $e) {
// something went wrong and it was not the service fault
}
}