From aeda9145522dd36b0232a6e3860f316318215f49 Mon Sep 17 00:00:00 2001 From: Anders Evenrud Date: Fri, 6 Jan 2017 19:41:28 +0100 Subject: [PATCH] server-php: Added better handling of core errors --- src/server/php/Core/Instance.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/server/php/Core/Instance.php b/src/server/php/Core/Instance.php index 8fb455a560..1d86342e95 100644 --- a/src/server/php/Core/Instance.php +++ b/src/server/php/Core/Instance.php @@ -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 ''; + print '

Error

';
+    print print_r([
+      'message' => $errstr,
+      'type' => $errno,
+      'file' => $errfile,
+      'line' => $errline
+    ], true);
+    print '
'; + exit; } /** @@ -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__ . '/../../'));