$factory = new Ejsmont\CircuitBreaker\Factory();
$circuitBreaker = $factory->getSingleApcInstance(30, 300);
$userProfile = null;
if( $circuitBreaker->isAvailable("UserProfileService") ){
try{
$userProfile = $userProfileService->loadProfileOrWhatever();
$circuitBreaker->reportSuccess("UserProfileService");
}catch( UserProfileServiceConnectionException $e ){
// network failed - report it as failure
$circuitBreaker->reportFailure("UserProfileService");
}catch( Exception $e ){
// something went wrong but it is not service's fault,
// dont report as failure
}
}
if( $userProfile === null ){
// for example, show 'System maintenance, you cant login now.' message
// but still let people buy as logged out customers.
}