jesugmz / http-health-check
Simple HTTP health check written in PHP
v1.0.0
2018-07-20 00:46 UTC
Requires
- php: ^7.1
- guzzlehttp/guzzle: ^6.3.3
Requires (Dev)
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-09-21 21:16:54 UTC
README
HTTP Health Check is a simple HTTP health check written in PHP built on top of Guzzle.
- Easy way to check HTTP services status by status code and body content from your PHP application
- Grant finite HTTP request timeout (Guzzle does not)
- Positive behavior by default. If no conditions are provided, the health will be consider healthy as soon as the request can be made successfully - no connectivity issues
Installation
Install the latest version through Composer:
$ composer require jesugmz/http-health-check
Usage
HTTP Health Check will do a GET request to the given endpoint URL and can check the following conditions in the response:
- HTTP status code: expressed as
status_code_equals_to
- Body content: plain text that appears in the body response and is expressed as
body_contains
use HttpHealthCheck\HttpHealthCheck; $endpointUrl = 'https://github.com/jesuGMZ/'; $conditions = [ 'status_code_equals_to' => 200, 'body_contains' => 'jesuGMZ', ]; $check = new HttpHealthCheck($endpointUrl, $conditions); var_dump($check->isHealthy());
It allows also Guzzle Request Options parameters:
use HttpHealthCheck\HttpHealthCheck; $endpointUrl = 'https://mdn.github.io/learning-area/javascript/oojs/json/superheroes.json'; $conditions = [ 'status_code_equals_to' => 200, 'body_contains' => 'Super hero squad', ]; $options = [ 'headers' => [ 'User-Agent' => 'My custom user agent', 'Accept' => 'application/json', ] ]; $check = new HttpHealthCheck($endpointUrl, $conditions, $options); var_dump($check->isHealthy());