PHP code example of ovenlab / cakephp-health

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

    

ovenlab / cakephp-health example snippets


// src/Application.php
public function bootstrap(): void
{
    parent::bootstrap();
    $this->addPlugin('Health');
}

use Health\Check\CacheCheck;
use Health\Check\DatabaseCheck;
use Health\Check\DiskSpaceCheck;

return [
    'Health' => [
        'checks' => [
            'database' => ['className' => DatabaseCheck::class, 'connection' => 'default'],
            'cache' => ['className' => CacheCheck::class, 'config' => 'default'],
            'disk' => [
                'className' => DiskSpaceCheck::class,
                'path' => TMP,
                'warningThreshold' => 80,  // percent used
                'criticalThreshold' => 95,
            ],
        ],
        'guard' => [
            'token' => env('HEALTH_TOKEN'),
            'allowIp' => [],
        ],
    ],
];

namespace App\Health;

use Health\Check\HealthCheckInterface;
use Health\Check\Result;

class QueueDepthCheck implements HealthCheckInterface
{
    public function __construct(private array $options = [])
    {
    }

    public function name(): string
    {
        return 'queue';
    }

    public function run(): Result
    {
        $depth = /* ... */ 0;
        $max = $this->options['max'] ?? 1000;

        if ($depth >= $max) {
            return Result::critical("Queue backlog is {$depth}", ['depth' => $depth]);
        }

        return Result::ok("Queue backlog is {$depth}", ['depth' => $depth]);
    }
}

'queue' => ['className' => \App\Health\QueueDepthCheck::class, 'max' => 500],
bash
cp vendor/ovenlab/cakephp-health/config/health.example.php config/health.php