PHP code example of fabiomsouto / phuse

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

    

fabiomsouto / phuse example snippets


$M = 10;
$T = 100;
$R = 1000;
$fuse = FuseBox::getUnsafeApcInstance("database", $M, $T, $R);

$M = 10;
$T = 100;
$R = 1000;
$fuse = FuseBox::getUnsafeApcInstance("database", $M, $T, $R);
if ($fuse->ok()) {
    // do whatever
}

$M = 10;
$T = 100;
$R = 1000;
$fuse = FuseBox::getUnsafeApcInstance("database", $M, $T, $R);

...

try {
   $result = $curl->post($url, $data);
}
catch (Exception $e) {
    $fuse->melt();
}

class AFuseObserver implements SplObserver {
    public function update(SplSubject $subject)
    {
        $blown = $subject->blown();
        echo "This fuse is now ";
        echo $blown? "blown\n" : "not blown\n";
    }
}

...

$M = 10;
$T = 100;
$R = 1000;
$fuse = FuseBox::getUnsafeApcInstance("database", $M, $T, $R);
$observer = new AFuseObserver();
$fuse->attach($observer);

// when the fuse melts you will see something in your terminal
$fuse->melt();
// outputs "This fuse is now blown" when the threshold is reached

...
// after 1000ms...
$fuse->ok();
// outputs "This fuse is now not blown" when the restart period ends