簡體   English   中英

為什么這個PHP錯誤腳本沒有通過電子郵件發送致命錯誤?

[英]Why is this PHP error script not emailing me for fatal errors?

我正在使用nettuts的以下腳本:

// Our custom error handler  
function error_engine($number, $message, $file, $line, $vars)  

{  
    $email = " 
        <p>An error ($number) occurred on line  
        <strong>$line</strong> and in the <strong>file: $file.</strong>  
        <p> $message </p>";  

    $email .= "<pre>" . print_r($vars, 1) . "</pre>";  

    $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

    // Email the error to someone...  
    error_log($email, 1, 'example@example.com', $headers);  


    if ( ($number !== E_NOTICE) && ($number < 2048) ) {  
        die("There was an error. Please try again later.");  
    }  
}  

// We should use our custom function to handle errors.  
set_error_handler('error_engine'); 

它可以很好地用於通知和警告之類的東西,但是當我故意破壞腳本時,例如說將“ mysqli_connect”更改為“ mysqy_connct”,我會在屏幕上看到致命錯誤,並且沒有電子郵件!

這樣的錯誤是否超出了此類錯誤記錄/報告的范圍?

我究竟做錯了什么?

set_error_handler/set_exception_handler不能處理所有可能的錯誤。 即,解析錯誤不會被它捕獲。 我無法確切告訴您它無法解決的問題。 一般規則是,當try catch可能捕獲的某些內容或調用trigger_error時,將調用這些處理程序

捕獲set_error_handler/set_exception_handler未捕獲的錯誤許多框架使用register_shutdown_functionerror_get_last的組合

它在文檔中列出:

用戶定義的函數無法處理以下錯誤類型:E_ERROR,E_PARSE,E_CORE_ERROR,E_CORE_WARNING,E_COMPILE_ERROR,E_COMPILE_WARNING,以及在調用set_error_handler()的文件中引發的大多數E_STRICT。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM