I can use set_error_handler()
to catch most PHP errors, but it doesn\'t work for fatal (E_ERROR
) errors, such as calling a function that doesn\'t e
Log fatal errors using the register_shutdown_function
, which requires PHP 5.2+:
register_shutdown_function( "fatal_handler" );
function fatal_handler() {
$errfile = "unknown file";
$errstr = "shutdown";
$errno = E_CORE_ERROR;
$errline = 0;
$error = error_get_last();
if($error !== NULL) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
error_mail(format_error( $errno, $errstr, $errfile, $errline));
}
}
You will have to define the error_mail
and format_error
functions. For example:
function format_error( $errno, $errstr, $errfile, $errline ) {
$trace = print_r( debug_backtrace( false ), true );
$content = "
Item Description
Error
$errstr
Errno
$errno
File
$errfile
Line
$errline
Trace
$trace
";
return $content;
}
Use Swift Mailer to write the error_mail
function.
See also: