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


return [
    'memcached-server' => [
        'host' => '127.0.0.1',
        'port' => 11211
    ],
    'circuit-breaker' => [
        'failure-threshold' => 5,
        'half-open-timeout' => 5,
        'timeout' => 10
    ]
];

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 */
}
bash
php artisan vendor:publish --tag="circuit-breaker-config"