PHP error_log() 函式
示例
將錯誤訊息傳送到 Web 伺服器的錯誤日誌以及郵件帳戶
<?php
// 連線資料庫失敗時,將錯誤訊息傳送到伺服器日誌
if (!mysqli_connect("localhost","bad_user","bad_password","my_db")) {
error_log("Failed to connect to database!", 0);
}
// 當 FOO 用完時,向管理員傳送電子郵件
if (!($foo = allocate_new_foo())) {
error_log("Oh no! We are out of FOOs!", 1, "admin@example.com");
}
?>
定義和用法
error_log() 函式將錯誤訊息傳送到日誌、檔案或郵件帳戶。
語法
error_log(message, type, destination, headers);
引數值
引數 | 描述 |
---|---|
message | 必需。指定要記錄的錯誤訊息 |
type | 可選。指定錯誤訊息的去向。可能的值
|
destination | 可選。指定錯誤訊息的傳送目的地。此值取決於 type 引數的值。 |
headers | 可選。僅當 type 引數設定為 1 時使用。指定額外的郵件頭,例如 From、Cc 和 Bcc。多個郵件頭應以 CRLF (\r\n) 分隔。 |
技術詳情
返回值 | 成功時為 TRUE。失敗時為 FALSE |
---|---|
PHP 版本 | 4.0+ |
二進位制安全 | 否 |
PHP 更新日誌 | PHP 5.2.7:值 4 被新增到 type 引數中。 |
PHP 錯誤參考