Simple Drupal monitor script (avoid full bootstrap, check DB and cache availability)
<?php
// OH HAI THARE
// NO CACH PLZ
header( "Cache-Control: no-cache, max-age=0, must-revalidate");
// SET ERROR HANDLR
set_error_handler('monitor_handle_error');
// CAN HAS DRUPAL BOOTSTRAP?
define('DRUPAL_ROOT', __DIR__);
chdir(DRUPAL_ROOT);
require_once 'includes/bootstrap.inc';
try {
// CAN HAS CONFIGURSHION?
drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION);
// RESET ERROR HANDLR CUZ BOOTSTRAP OVERRIDE IT
set_error_handler('monitor_handle_error');
// CAN HAS DATABAZ?
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
Database::getConnection();
// CAN HAS CACHE?
cache_get('monitor');
// AWSUM, EVRYTHIN IZ K
print 'UP';
}
catch (Exception $e) {
// EXCEPSHUN KATCHD, TRIGGR AN ERROR
trigger_error($e->getMessage(), E_USER_ERROR);
}
// ERROR HANDLR
function monitor_handle_error($errno, $errstr, $errfile, $errline, $errcontext) {
// LETS DYE REPORTIN FAILURE
header("{$_SERVER['SERVER_PROTOCOL']} 500 FAIL");
die('FAIL');
}
// KTHXBYE
Written by Pierre Buyle
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Drupal
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#