wunderio / drupal-ping
Drupal health check endpoint for load balancers
Installs: 232 237
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 8
Forks: 4
Open Issues: 15
Type:web-dropin
pkg:composer/wunderio/drupal-ping
Requires
- composer/composer: ^2
- drupal/core: ^8 || ^9 || ^10 || ^11
- koodimonni/composer-dropin-installer: ^1
- dev-master
- 7.x-dev
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.0.2
- 1.0.1
- 1.0
- dev-hotfix/custom-pinger-example
- dev-feature/+47-streamline-development-process
- dev-feature/44-Better-handling-for-Memcache
- dev-feature/+44-Better-handling-for-Memcache
- dev-feature/testing-refactor
- dev-feature/parallel-cleanup
This package is auto-updated.
Last update: 2025-10-05 11:38:43 UTC
README
This script can be used for Drupal8 through Drupal11 uptime monitoring. It is not suitable for subsystem health-checks for things like container or load balancer.
Installation
- Add this to your
composer.json:
{
"extra": {
"dropin-paths": {
"web/": [
"type:web-dropin",
"package:wunderio/drupal-ping:_ping.php"
]
}
}
}
- Then install the composer package as usual with:
composer require wunderio/drupal-ping:^2
- Add
_ping.phpinto the main project's.gitignore.
Changelog
See Releases.
Usage
- Visit
/_ping.phpto get a system status - By using
?debug=tokenadditional status check table and time profiling information is displayed- See Debug Mode how to obtain the
tokenvalue
- See Debug Mode how to obtain the
- Find slow checks and checks errors in logs
Checks
Main database
User #1 record is fetched from the database.
Memcache
Assumes $settings['memcache']['servers'] presence in the settings.php.
Following statuses are issued:
disabled- No memcached servers defined in settingssuccess- All connections succeedwarning- At least one connection succeeds, at least one connection failserror- All connections fail
Basic networking is used, no Memcached or Memcache class.
Redis
By using Redis class, connection is established to the server.
In settings.php following has to be defined:
$settings['redis.connection']['host']$settings['redis.connection']['port']
This test works on both TCP and Unix Sockets.
For the latter only host has to be defined as path.
Elasticsearch
In settings.php following has to be defined:
$settings['ping_elasticsearch_connections'] = [
[
'host' => 'hostname',
'port' => 1234,
'proto' => 'http', // http or https
'severity' => 'warning', // warning or error
],
];
Elasticsearch check requires separate setting, because there are too many ways
how Elasticsearch config can be defined in the settings.php file, depending
on many factors.
The connection is establised by PHP curl, and then /_cluster/health is
being visited. The check expects to get green status in the response.
Following statuses are issued:
disabled- No Elasticsearch servers defined in settingssuccess- All connections succeedwarning- At least one connection failed, and all failed connections have been configured with 'severity' = 'warning'error- At least one connection failed, and at least one of the failed connections have been configured with 'severity' = 'error'
FS Scheme
Consists of 3 tests:
- Check if a file can be created within the public filesystem.
- Check if the test-file can be deleted from the public filesystem.
- Check if there are any leftover test-files, and remove them.
Custom ping
If a site needs any custom checks, then just create _ping.custom.php.
Use of $status->setName() and $status->set() to define the result.
The PHP file does not need to contain functions, just plain PHP is enough.
Check it out how other checks are created in the _ping.php.
Debug Mode
_ping.php can be accessed over the web.
For example https://example.com/_ping.php.
It can also be accessed from the shell cd /path/web ; php _ping.php.
From the shell output the debug token can be attained.
Then visit the ping again with https://example.com/_ping.php?debug=token.
The token is generated in one of the following ways. These methods are listed by precedance. If earlier fails (is empty), then next one is tried.
- Drupal settings
$settings['ping_token'] - Environment variable
PING_TOKEN - Md5 of the combination of environment variable values where the variable names matches regex
/^(DB|ENVIRONMENT_NAME|GIT|PHP|PROJECT_NAME|S+MTP|VARNISH|WARDEN)/- NB! This method assumes environment variable consistency between webserver and shell. - Md5 of Drupal settings
$settings['hash_salt'] - Md5 of the hostname
Ping Development & Testing
Setting up development environment
- Clone development and testing environment
git clone git@github.com:wunderio/drupal-project.git ~/projects/drupal-ping- Yes, save it as
drupal-ping.
cd drupal-ping/- Clone the ping project itself
git clone git@github.com:wunderio/drupal-ping.git- Yes, save it as
drupal-pingtoo, inside the folder of the same name. It is the actual repo we are going to work with. - Checkout or create your development branch.
- Link
.lando.yml
rm -f .lando.yml- at the top-level folder, remove the Lando conf file.ln drupal-ping/.lando.yml- link the Lando conf from the ping repo folder. Don't create this as a soft (-s) link because Lando would mount the project where the original file is. Therefore create the hard link which is indistinguishable for Lando.
- Link
.lando/
rm -rf .lando- at the top-level folder, remove the Lando folder.ln -s drupal-ping/.lando- link the Lando scripts folder from the ping repo folder.
lando start- Note that the Drupal install will mess up
settings.phpa bit, don't commit. - https://ping.lndo.site/_ping.php
lando scanlando test
Development commands
lando test- Execute phpunit testslando scan- Run coding standard checks
Maintainers
License
MIT