PHP code example of gritzkoo / php-health-checker

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

    

gritzkoo / php-health-checker example snippets




ritzkoo\HealthChecker\Check;
use Gritzkoo\HealthChecker\HealthChecker;

$checker = new HealthChecker([
    // optional prop, will be used to readiness response
    'name' => 'My application name', 
    // version is used in liveness and readiness actions
    'version' => 'v1.0.0', // more details in version section of this document!
    // the list of checks you whant to test, is just an array of array with name and handle function
    'integrations' => [
        [
            // the name of the integration you are trying to verify
            'name' => 'github status check',
            // here is just an example of how to make your own check
            // you can inject this function the way you want, you only need to return
            // a instance of Gritzkoo\HealthChecker\Check
            // The HealthCheker will interpret your check fails when the $check->error is not empty
            'handle' => function () {
                $check = new Check([
                    'url' => 'https://github.com/status'
                ]);
                $ch = curl_init($check->url);
                try {
                    $response = curl_exec($ch);
                } catch (Exception $e) {
                    $check->error = $e;
                }
                $info = curl_getinfo($ch);
                curl_close($ch);
                if ($info['http_code'] != 200) {
                    $check->error = [
                        'response' => $response,
                        'info' => $info
                    ];
                }
                return $check;
            }
        ]
    ]
]);