Skip to content

Commit

Permalink
server-php: Added better handling of core errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Jan 6, 2017
1 parent e8f6a37 commit aeda914
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/server/php/Core/Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,36 @@ final public static function GetVFSModules() {
* @return void
*/
final public static function shutdown() {
if ( !is_null($error = error_get_last()) ) {
self::handle($error['type'], $error['message'], $error['file'], $error['line']);
}
}

/**
* Error handler
* @access public
* @return void
*/
final public static function handle($errno, $errstr, $errfile, $errline) {
@header_remove();

while ( ob_get_level() ) {
ob_end_flush();
}

header('HTTP/1.0 500 Internal Server Error');
header('Content-type: text/html');

print '<html><head></head><body>';
print '<h1>Error</h1><pre>';
print print_r([
'message' => $errstr,
'type' => $errno,
'file' => $errfile,
'line' => $errline
], true);
print '</pre></body></html>';
exit;
}

/**
Expand Down Expand Up @@ -216,6 +246,7 @@ final public static function run() {
}

register_shutdown_function([__CLASS__, 'shutdown']);
set_error_handler([__CLASS__, 'handle']);

define('DIR_ROOT', realpath(__DIR__ . '/../../../../'));
define('DIR_SERVER', realpath(__DIR__ . '/../../'));
Expand Down

0 comments on commit aeda914

Please sign in to comment.