PHP code example of leonardovee / laravel-circuit-breaker
1. Go to this page and download the library: Download leonardovee/laravel-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/ */
leonardovee / laravel-circuit-breaker example snippets
use LeonardoVee\CircuitBreaker\CircuitBreaker;
try {
/** Make the request to your service */
Http::get('https://my-service.com');
/** Register a success on the circuit breaker */
CircuitBreaker::setSuccess(circuitName: 'https://my-service.com');
} catch (Throwable $throwable) {
/** Register a failure on the circuit breaker */
CircuitBreaker::setFailure(circuitName: 'https://my-service.com');
}
/** Use to verify if the circuit is closed or open */
if (CircuitBreaker::isAvailable(circuitName: 'https://my-service.com')) {
/** Do stuff */
}