PHP code example of enklare-development / healthcheck-helper

1. Go to this page and download the library: Download enklare-development/healthcheck-helper 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/ */

    

enklare-development / healthcheck-helper example snippets



namespace App\Http\Controllers;
use \Enklare\Health\HealthCheck;
use \Enklare\Health\BasicHealthCheck;

class HealthController
{

    /**
     * Just nice to have in an API health department
     **/
    public function ping()
    {
        return response(null, 204);
    }

    /**
     * Status healthcheck function
     **/
    public function status()
    {
        $check = new HealthCheck('my-awesome-service', "1.0.0");
        $check->addCheck($this->_checkDatabase());
        $check->addCheck($this->_checkRedis());
        return response()->json($check, 200);
    }

    private function _checkDatabase()
    {
        $check = new BasicHealthCheck('database');
        return SomeCoolHelper::isDatabaseReady() ? $check->passed(): $check->failed();
    }

    private function _checkRedis()
    {
        $check = new BasicHealthCheck('redis');
        return SomeCoolHelper::isRedisReady() ? $check->passed(): $check->failed();
    }
}