error_log
(PHP 4, PHP 5, PHP 7, PHP 8)
error_log — 發送錯誤資訊到某個地方
說明
   error_log(
string
int
string
string
): bool
  string
$message,int
$message_type = 0,string
$destination = ?,string
$extra_headers = ?): bool
把錯誤資訊發送到 web 伺服器的錯誤日誌,或者到一個檔案里。
參數
- 
message
- 
      應該被記錄的錯誤資訊。 
- 
message_type
- 
      設定錯誤應該發送到何處。可能的資訊型別有以下幾個: error_log() 日誌型別 0 message發送到 PHP 的系統日誌,使用 操作系統的日誌機制或者一個檔案,取決於 error_log 指令設定了什麼。 這是個預設的選項。1 message發送到參數destination設定的郵件地址。 第四個參數extra_headers只有在這個型別里才會被用到。2 不再是一個選項。 3 message被髮送到位置為destination的檔案里。 字元message不會預設被當做新的一行。4 message直接發送到 SAPI 的日誌處理程式中。
- 
destination
- 
      目標。它的含義描述于以上,由 message_type參數所決定。
- 
extra_headers
- 
      額外的頭。當 message_type設定為1的時候使用。 該資訊型別使用了 mail() 的同一個內建函式。
返回值
   成功時返回 true, 或者在失敗時返回 false。
  
註釋
警告
   
  
    error_log() 並非二進制安全的。null 字元可能截斷 message。
   
小技巧
   
 
    message 不能包含 null 字元。
    注意,message 可能會發送到檔案、郵件、syslog 等。
    所以在呼叫 error_log() 前需要使用適合的轉換/轉義函式: base64_encode()、 rawurlencode() 或 addslashes()。
   
範例
示例 #1 error_log() 範例
<?php
// 如果無法連線到數據庫,發送通知到伺服器日誌
if (!Ora_Logon($username, $password)) {
    error_log("Oracle database not available!", 0);
}
// 如果用盡了 FOO,通過郵件通知管理員
if (!($foo = allocate_new_foo())) {
    error_log("Big trouble, we're all out of FOOs!", 1,
               "[email protected]");
}
// 呼叫 error_log() 的另一種方式:
error_log("You messed up!", 3, "/var/tmp/my-errors.log");
?>
更新日誌
| 版本 | 說明 | 
|---|---|
| 5.2.7 | 可能的值:4新增到了 message_type。 |