PHP code example of ilyaplot / pulse

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

    

ilyaplot / pulse example snippets


$pulse->addWarning(new ClosureRule(
    fn() => (new YoutubeClient())->isUp(),
    "Verify connectivity to youtube",
    LevelEnum::warning,
));

$pulse->addInfo(new ClosureRule(
    fn() => (new YoutubeClient())->isUp(),
    "Verify connectivity to youtube", 
));

$pulse->addInfo(new ClosureRule(
    function(ClosureRule $closureRule) {
        $this->setErrorMessage( date('l'));
        return false;
    }, 
    "Today is",
));

$result = $pulse->run();

class YoutubeRule extends AbstractRule
{
    public function __construct(
        private readonly string $apiKey,
    ) {
        $this->description = 'Verify connectivity to youtube';
        $this->level = LevelEnum::warning;
    }
    
    public function run(): bool
    {
        $youtubeClient = new YoutubeClient($this->apiKey);
        try {
            return $youtubeClient->isUp(); // bool
        } catch (AuthenticationException) {
            $this->setErrorMessage('Invalid API key');
            return false;
        }
    }
}

$pulse->add(new YoutubeRule('your-api-key-1'));
$pulse->add(new YoutubeRule('your-api-key-2'));

$pulse = new ilyaplot\pulse\Pulse();

$pulse->add(new FileRule(
    '/path/to/your/config/file',
    description: "Check that config file is readable",
    checkIsReadable: true,
));

t'])){
            return false;
        }
        $key = 'healthcheck_test_key'
        $msg = 'memcache is working';
        $memcache->set($key, $msg);
        return $memcache->get($key) === $msg;
    }, 
    "Check memcache connectivity"
));