目录

PHP error_log() 函数

PHP 错误参考

示例

将错误消息发送到 Web 服务器的错误日志和邮件帐户:

<?php
// Send error message to the server log if error connecting to the database
if (!mysqli_connect("localhost","bad_user","bad_password","my_db")) {
    error_log("Failed to connect to database!", 0);
}

// Send email to administrator if we run out of 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);

参数值

Parameter Description
message Required. Specifies the error message to log
type Optional. Specifies where the error message should go. Possible values:
  • 0 - Default. Message is sent to PHP's system logger, using the OS' system logging mechanism or a file, depending on what the error_log configuration is set to in php.ini
  • 1 - Message is sent by email to the address in the destination parameter
  • 2 - No longer in use (only available in PHP 3)
  • 3 - Message is appended to the file specified in destination
  • 4 - Message is sent directly to the SAPI logging handler
destination Optional. Specifies the destination of the error message. This value depends on the value of the type parameter
headers Optional. Only used if the type parameter is set to 1. Specifies additional headers, like From, Cc, and Bcc. Multiple headers should be separated with a CRLF (\r\n)


技术细节

返回值: 成功则为真。失败时为 FALSE
PHP 版本: 4.0+
二进制安全:
PHP 变更日志: PHP 5.2.7:值 4 被添加到类型范围

PHP 错误参考