Last active
August 29, 2015 14:04
-
-
Save pbuyle/8b6c2610b6a6affc5546 to your computer and use it in GitHub Desktop.
Simple Drupal monitor script (avoid full bootstrap, check DB and cache availability)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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