Skip to content

Instantly share code, notes, and snippets.

@pbuyle
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbuyle/8b6c2610b6a6affc5546 to your computer and use it in GitHub Desktop.
Save pbuyle/8b6c2610b6a6affc5546 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment