Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Last active December 30, 2015 09:19
Show Gist options
  • Save NoMan2000/7808718 to your computer and use it in GitHub Desktop.
Save NoMan2000/7808718 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Sets up debugging tools, if enabled.
* PHP Debug is very powerful, but you have to configure numerous files to get it to work.
*/
// Enable or disable debugging tools.
$tools = array(
'chromephp' => FALSE,
'firephp' => FALSE,
'phpdebug' => FALSE,
);
/*
* Only use these to test out the debugger. Do not use otherwise.
* trigger_error('Custom notice', E_USER_NOTICE);
* trigger_error('Custom warning', E_USER_WARNING);
* trigger_error('Custom error', E_USER_ERROR);
*/
// ChromePHP.
if ($tools['chromephp']) {
// See http://www.chromephp.com for more details.
require_once 'chromephp/ChromePhp.php';
ob_start();
}
// FirePHP.
if ($tools['firephp']) {
// See http://www.firephp.org/HQ/Learn.htm for more details.
require_once 'FirePHPCore/FirePHP.class.php';
ob_start();
}
// PHP_Debug.
if ($tools['phpdebug']) {
// Set paths, configuration.
$php_debug_options = array(
'HTML_DIV_images_path' => 'PHP_Debug/images',
'HTML_DIV_css_path' => 'PHP_Debug/css',
'HTML_DIV_js_path' => 'PHP_Debug/js',
'HTML_DIV_view_source_script_path' => 'PHP_Debug',
'replace_errorhandler' => TRUE,
'allow_url_access' => TRUE,
);
set_include_path(get_include_path() . PATH_SEPARATOR . 'PHP_Debug');
require_once 'PHP_Debug/PHP/Debug.php';
global $PHP_Debug;
$PHP_Debug = new PHP_Debug($php_debug_options);
}
/**
* Send a notification on a shutdown caused by an error.
*/
register_shutdown_function('shutdown_notify');
$person1 = "";
$person2 = "";
function shutdown_notify() {
$error = error_get_last();
if (!empty($error) && in_array($error['type'], array(E_ERROR, E_USER_ERROR))) {
echo '<h1>Sorry, something went horribly wrong; the team has been notified.</h1>';
$to = "{$person1}, {$person2}";
$subject = "[{$_SERVER['SERVER_NAME']}] Fatal error in {$error['file']} on line {$error['line']}";
$message = var_export($error, TRUE) . PHP_EOL;
$message .= var_export($_SERVER, TRUE) . PHP_EOL;
$headers = 'From: donot-reply@example.com' . "\r\n" .
mail($to, $subject, $message, $headers);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment