Skip to content

Commit aeda914

Browse files
committed
server-php: Added better handling of core errors
1 parent e8f6a37 commit aeda914

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/server/php/Core/Instance.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,36 @@ final public static function GetVFSModules() {
186186
* @return void
187187
*/
188188
final public static function shutdown() {
189+
if ( !is_null($error = error_get_last()) ) {
190+
self::handle($error['type'], $error['message'], $error['file'], $error['line']);
191+
}
192+
}
193+
194+
/**
195+
* Error handler
196+
* @access public
197+
* @return void
198+
*/
199+
final public static function handle($errno, $errstr, $errfile, $errline) {
200+
@header_remove();
201+
202+
while ( ob_get_level() ) {
203+
ob_end_flush();
204+
}
205+
206+
header('HTTP/1.0 500 Internal Server Error');
207+
header('Content-type: text/html');
208+
209+
print '<html><head></head><body>';
210+
print '<h1>Error</h1><pre>';
211+
print print_r([
212+
'message' => $errstr,
213+
'type' => $errno,
214+
'file' => $errfile,
215+
'line' => $errline
216+
], true);
217+
print '</pre></body></html>';
218+
exit;
189219
}
190220

191221
/**
@@ -216,6 +246,7 @@ final public static function run() {
216246
}
217247

218248
register_shutdown_function([__CLASS__, 'shutdown']);
249+
set_error_handler([__CLASS__, 'handle']);
219250

220251
define('DIR_ROOT', realpath(__DIR__ . '/../../../../'));
221252
define('DIR_SERVER', realpath(__DIR__ . '/../../'));

0 commit comments

Comments
 (0)