PHP code example of tourze / health-check-bundle

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

    

tourze / health-check-bundle example snippets


     HealthCheckBundle\HealthCheckBundle::class => ['all' => true],
     



use Laminas\Diagnostics\Check\CheckInterface;
use Laminas\Diagnostics\Result\ResultInterface;
use Laminas\Diagnostics\Result\Success;
use Laminas\Diagnostics\Result\Failure;

class CustomChecker implements CheckInterface
{
    public function check(): ResultInterface
    {
        // Your custom logic here
        if ($condition) {
            return new Success('Check passed');
        }
        
        return new Failure('Check failed');
    }
    
    public function getLabel(): string
    {
        return 'Custom Health Check';
    }
}

// Example: Check active user count
$sqlChecker = new SqlChecker();
$sqlChecker->setName('Active Users Check');
$sqlChecker->setSql('SELECT COUNT(*) FROM users WHERE active = 1');
$sqlChecker->setOperator(SqlOperatorEnum::GT);
$sqlChecker->setCompareValue(0);
$sqlChecker->setCronExpression('0 */5 * * * *'); // Every 5 minutes
bash
   php bin/console health-check:run