PHP error_log() 函数

实例

把错误消息发送到 web 服务器日志和邮件账号:

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");
}
?> 

Definition and Usage

The error_log() function sends error messages to the server error log, file, or remote target.

Syntax

error_log(message,type,destination,headers);
Parameters Description
message Required. Specifies the error message to be logged.
type

Optional. Specifies where the error should be sent. Possible values:

  • 0 - Default. The message is sent to PHP's system log, using the operating system's logging mechanism or a file, depending on how the error_log directive is set in php.ini.
  • 1 - The message is sent to the parameter destination The email address set. The fourth parameter extra_headers It is only used in this type.
  • 2 - No longer used (used only in PHP 3)
  • 3 - The message is sent to the location of destination file. Character message It will not be default to be treated as a new line.
  • 4 - The message is sent directly to the SAPI log handler.
destination Optional. Specifies the target of the error message. The value is determined by type The value of the parameter determines.
headers

Optional. Specifies additional headers, such as From, Cc, and Bcc. This information type uses the same built-in function as mail().

Only when message_type Used when set to 1.

CRLF (\r\n) should be used to separate multiple headers.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 4.0+
PHP Update Log: PHP 5.2.7: Possible values: 4 Added to type Parameters.