PHP code example of ipunkt / laravel-healthcheck

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

    

ipunkt / laravel-healthcheck example snippets


class ServiceProvider {
	public function boot() {

		/**
		 * @var HealthcheckerFactory $factory
		 */
		$factory = $this->app->make('Ipunkt\LaravelHealthcheck\HealthChecker\Factory\HealthcheckerFactory');

		$factory->register('identifier', function(array $config) {

			$newChecker = new ExampleChecker;

			$newChecker->setExampleOption( array_get($config, 'url', 'http://www.example.com') );

			return $newChecker;

		});

	}
}

class ExampleChecker implement Ipunkt\LaravelHealthcheck\HealthChecker\Checker {

	protected $url;

	public function setExampleOption($url) {
		$this->url = $url;
	}

	public function check() {
		$url = $this->url;
		if ( @file_get_contents($url) === false )
			throw new CheckFailedException("Failed to retrieve $url.");
	}
}