PHP code example of mt-olympus / cerberus
1. Go to this page and download the library: Download mt-olympus/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/ */
mt-olympus / cerberus example snippets
'factories' => [
Cerberus\Cerberus::class => Cerberus\Factory::class
],
return [
'cerberus' => [
'max_failues' => 5,
'timeout' => 60,
'storage' => [
'adapter' => [
'name' => 'filesystem',
'options' => [
'cache_dir' => 'data/cache',
'namespace' => 'my_project'
]
],
'plugins' => [
// Don't throw exceptions on cache errors
'exception_handler' => [
'throw_exceptions' => false
]
]
]
]
];
$storage = StorageFactory::factory($storageConfig);
$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');
}
}