This script can be used for Drupal8 and Drupal9 health-checks.
- Add this to your
composer.json
:
{
"extra": {
"dropin-paths": {
"web/": ["package:wunderio/drupal-ping:_ping.php"]
}
}
}
- Then install the composer package as usual with:
composer require wunderio/drupal-ping:^2
- Add
_ping.php
into the main project's.gitignore
.
- Refactor code into Classes
- Add comprehensive test coverage
- Fix coding standard issues
Breaking Changes!
composer.json
:extra
:dropin-paths
has a new syntax!settings.php
: Elasticsearch has additional syntax for testing. See below.
- One can visit
/_ping.php
to get a status - By using
?debug=hash
query, one can get status check status table, and time profiling table. Thehash
is 4 first letters of the salt insettings.php
. - Find slow checks and checks errors in logs.
User #1 record is fetched from the database.
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.
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.
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'
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.
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
.
lando install
- Install dev dependencies without Drupallando start
- Install basic Drupal and serviceslando test
- Execute phpunit testslando scan
- Run coding standard checks
Note: the Lando setup is defined so that D7 and D89 branched can be easily switched both running their own own setup. Drupal and composer installations wont clash. They have separate dirs.
_ping.php
can be accessed over the lando url.
For example http://localhost:51418/_ping.php
.
It can also be accessed from the shell cd /app/drupal9/web ; php _ping.php
.
From the shell output the debug code can be attained.
MIT