PHP code example of svilborg / laravel-health

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

    

svilborg / laravel-health example snippets


    return [
        /*
         * |--------------------------------------------------------------------------
         * | Health Checks
         * |--------------------------------------------------------------------------
         * |
         */

        'checks' => [
             [
                 'class' => \Health\Checks\NullCheck::class,
                 'params' => []
             ],
             [
                 'class' => \Health\Checks\Servers\Database::class,
                 'params' => []
             ],
             [
                 'class' => \Health\Checks\Filesystem\DiskSpace::class,
                 'params' => [
                    'path' => '/'
                 ]
             ],
             [
                'class' => \Health\Checks\Env\Environment::class,
                'params' => [
                     'APP_ENV' => 'testing'
                 ]
             ]
        ]
    ];

    Route::get('/health', 'Health\Controllers\HealthController@check');

    use Health\Checks\BaseCheck;
    use Health\Checks\HealthCheckInterface;

    class ServiceACheck extends BaseCheck implements HealthCheckInterface
    {

        /**
         *
         * {@inheritdoc}
         * @see \Health\Checks\HealthCheckInterface::call()
         */
        public function call()
        {
            $health = $this->getBuilder('Service A');

            if(!$this->serviceA->connect()) {
                $health->withData('error', 'Service A Failed')
                        ->down();
            }
            else {
                $health->up();
            }

            return $health->build();
        }
    }