Running an external health check has the benefits of not being tied into WordPress itself, so when checking the endpoint, it pings the application to get data about critical services like application errors, build information, MySQL, PHP, Object Cache, Status, and WordPress version information.
By default, only the errors, and status are returned:
GET: /meta/health-check/ {"errors":null,"status":"OK"}
To include the other parameters in the health check reponse, pass in the keys to the endpoint with a true value: ?build=1&mysql=1&php&object_cache=1&wp=1
Status Enumerations
The status can return the following:
- OK: Everything is good.
- WARN: MySQL or Object Cache has errors or the HTTP response code is between 400 & 500.
- FAILURE: The HTTP response code is between 500 & 600.
- UNKNOWN: Unknown response.
Health Check installation steps
Include the composer package: composer require frosty-media/wp-health-check
.
Additional requirements
Note:Composer’s autoloading should be including in your application’s bootstrap, in this case the wp-config.php
file.
You can replace the prefix “health-check” route in any of the following rules if you would like to use an alternative the the example /meta/health-check/?
.
Apache requirements
If running Apache, add the following to your .htaccess file (before any WordPress rules):
RewriteEngine On RewriteRule ^meta/health-check/?$ /vendor/frosty-media/wp-health-check/src/check.php [L]
Nginx requirements
If running Nginx, add the following to your sites conf rules:
rewrite ^/meta/health-check/?$ /vendor/frosty-media/wp-health-check/src/check.php last;
Optional requirements
If you would like to include the MU Plugin (which creates the internal REST API route wp-json/health/check?) Update your composer `scripts.post-update-cmd` with the code below, or run composer config scripts.post-update-cmd.0 "FrostyMedia\\WpHealthCheck\\Composer\\Scripts::postUpdate"
Note, that Basic Auth is required when hitting the internal REST API endpoint.
{ "scripts": { "post-update-cmd": [ "FrostyMedia\\WpHealthCheck\\Composer\\Scripts::postUpdate" ] } }
GitHub
Follow development on GitHub, submit issues, fork your own version or help make WP Health Check better.