1. 將錯誤記錄到指定的檔案中,配置過程如下
* 1). log_errors=on
* 2). error_log=/tmp/php_error.log
1.使用error_log()函數記錄錯誤記錄檔
error_log(‘要記錄的錯誤資訊!’);
header('content-type:text/html; charset=utf-8');//開啟所有的錯誤報表error_reporting(-1);//設定時區ini_set('date.timezone', 'PRC');//禁用頁面顯示錯誤ini_set('display_errors', 0);//開啟日誌記錄功能ini_set('log_errors', 1);//設定錯誤記錄檔儲存的位置ini_set('error_log', '/tmp/custom_error.log');//忽略重複的錯誤ini_set('ignore_repeated_errors', 'on');//忽略重複的錯誤來源ini_set('ignore_repeated_source', 'on');error_log('我要把你記錄到我的自訂錯誤記錄檔中'.date('Y-m-d H:i:s', time()));trigger_error('trigger_error-----我要把你記錄到我的系統錯誤記錄檔中'.date('Y-m-d H:i:s', time()), E_USER_NOTICE);settype($var, 'king');
2.將錯誤記錄到系統日誌中
* 1.ini_set('error_log', 'syslog');常用
方法一//開啟所有的錯誤報表error_reporting(-1);//禁用頁面顯示錯誤ini_set('display_errors', 0);//開啟日誌記錄功能ini_set('log_errors', 1);//設定錯誤記錄檔儲存的位置------(系統日誌)ini_set('error_log', 'syslog');//忽略重複的錯誤ini_set('ignore_repeated_errors', 'on');//忽略重複的錯誤來源ini_set('ignore_repeated_source', 'on');// error_log('error_log-----我要把你記錄到我的系統錯誤記錄檔中'.date('Y-m-d H:i:s', time()));trigger_error('trigger_error-----我要把你記錄到我的系統錯誤記錄檔中'.date('Y-m-d H:i:s', time()), E_USER_NOTICE);// settype($var, 'king');方法二//====================出於安全問題不用===========================//開啟到系統日誌的連結openlog('PHP5.6.0', LOG_PID, LOG_SYSLOG);syslog(LOG_ERR, 'this is a test syslog'.date('Y-m-d H:i:s', time()));closelog();
2.將錯誤記錄檔通過郵件發送
* 1.error_log('msg', 1, mail_addr); 第二個參數設定為1
** bool error_log ( string $message [, int $message_type = 0 [, string $destination [, string $extra_headers ]]] )
message應該被記錄的錯誤資訊。message_type設定錯誤應該發送到何處。可能的資訊類型有以下幾個:error_log() 日誌類型0 message 發送到 PHP 的系統日誌,使用 作業系統的日誌機制或者一個檔案,取決於 error_log 指令設定了什麼。 這是個預設的選項。1 message 發送到參數 destination 設定的郵件地址。 第四個參數 extra_headers 只有在這個類型裡才會被用到。2 不再是一個選項。3 message 被發送到位置為 destination 的檔案裡。 字元 message 不會預設被當做新的一行。4 message 直接發送到 SAPI 的Tlog程式中。destination目標。它的含義描述於以上,由 message_type 參數所決定。extra_headers額外的頭。當 message_type 設定為 1 的時候使用。 該資訊類型使用了 mail() 的同一個內建函數。
//開啟所有的錯誤報表error_reporting(-1);//禁用頁面顯示錯誤ini_set('display_errors', 0);//開啟日誌記錄功能ini_set('log_errors', 1);//忽略重複的錯誤ini_set('ignore_repeated_errors', 'on');//忽略重複的錯誤來源ini_set('ignore_repeated_source', 'on');//設定第二個參數為1將,使用郵件發送錯誤記錄檔資訊error_log('error_log-----我要把你記錄到我的系統錯誤記錄檔中'.date('Y-m-d H:i:s', time()), 1, '732578448@qq.com');
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。