PHP error_log() 函数
实例
把错误消息发送到 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");
}
?>
// 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);
参数值
| 参数 | 描述 | 
|---|---|
| message | 必需。规定要记录的错误消息。 | 
| type | 
 可选。规定错误应该发送到何处。可能的值: 
  | 
| destination | 可选。规定错误消息的目标。该值由 type 参数的值决定。 | 
| headers | 
 可选。规定额外的头,比如 From、Cc 和 Bcc。该信息类型使用了 mail() 的同一个内置函数。 仅当 message_type 设置为 1 的时候使用。 应当使用 CRLF (\r\n) 来分隔多个头。  | 
技术细节
| 返回值: | 若成功则返回 TRUE,失败则返回 FALSE。 | 
|---|---|
| PHP 版本: | 4.0+ | 
| PHP 更新日志: | PHP 5.2.7:可能的值:4 添加到了 type 参数。 | 
PHP Error 错误参考手册
