P粉5761849332023-08-28 11:12:14
Use register_shutdown_function
to log fatal errors, this 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 must 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
Error number
$errno
document
$Error file
OK
$Error line
track
$trace
表>";
return $content;
}
Use Swift Mailer to write the error_mail
function.
See also:
reply0Cancel