Override legacy fatal error message
When a PHP fatal error stops a request, Exponential shows its own error page with a reference number that is also written to the error log. You can replace that page with your own, without changing the kernel, by registering a fatal error handler.
Registering a handler
Add the handler to the global override settings/override/error.ini.append.php. A siteaccess override is not read: the handler is registered before the siteaccess is known.
[ErrorSettings-kernel] FatalErrorHandler=CustomFatalErrorHandlerClass::FatalErrorHandlerFunction
The value is a PHP callable: a public static method. Put the class in an active extension:
<?php
class CustomFatalErrorHandlerClass
{
public static function FatalErrorHandlerFunction()
{
header( 'HTTP/1.1 500 Internal Server Error' );
echo '<strong>Sorry!</strong> Something went wrong. The error has been logged.';
eZDisplayResult( null );
}
}
Then regenerate the autoloads and clear the INI cache:
php bin/php/ezpgenerateautoloads.php -e php bin/php/ezcache.php --clear-tag=ini
With Exponential Velocity, restart it (./console exp:velocity restart) so its workers load the new class.
How it is used
- The web kernel registers the callable when it starts, if is_callable() accepts it. When it is not callable (a typo, or the autoloads were not regenerated), the built-in error page is used.
- The setting is read for web requests. Console scripts register their own handler.
- The error itself is still written to the error log; the handler only changes what the visitor sees. To find a logged error by the reference a visitor reports, see Finding an error by its reference.
Related pages
Contributors
- Sarah Haïm-Lubczanski
- Graham Brookins Updated Maintainer
Comments
Add a comment