PHP code example of los / cerberus

1. Go to this page and download the library: Download los/cerberus 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/ */

    

los / cerberus example snippets


'factories' => [
    Los\Cerberus\Cerberus::class => Los\Cerberus\CerberusFactory::class
],

return [
    'cerberus' => [
        'max_failures' => 5,
        'timeout' => 60,
    ]
];

$container->get(\Psr\SimpleCache\CacheInterface::class)

$storage = new Cache(); // Any psr/simple-cache implementation
$cerberus = new Cerberus($storage, 5, 60);

if ($cerberus->isAvailable()) {
    try {
        $http->makeRequest();
        $cerberus->reportSuccess();
    } catch (\Exception $ex) {
        $cerberus->reportFailure();
    }
}

if ($cerberus->isAvailable('service-one')) {
    try {
        $http->makeRequest();
        $cerberus->reportSuccess('service-one');
    } catch (\Exception $ex) {
        $cerberus->reportFailure('service-one');
    }
}

if ($cerberus->isAvailable('service-two')) {
    try {
        $http->makeRequest();
        $cerberus->reportSuccess('service-two');
    } catch (\Exception $ex) {
        $cerberus->reportFailure('service-two');
    }
}