PHP 中的 error_log() 函数
phpprogrammingserver side programming更新于 2025/12/1 1:38:00
error_log() 函数将错误发送到服务器错误日志、文件或远程目标。
语法
error_log(message, message_type, destination, extra_headers)
参数
message − 应记录的错误消息。
message_type − 它说明错误应该去哪里。可能的消息类型如下
0 − 默认。错误将发送到服务器日志系统或文件,具体取决于 php.ini 文件中 error_log 配置的设置方式
1 − 错误通过电子邮件发送到目标参数中的地址。此消息类型是唯一使用 headers 参数的消息类型
2 − 错误通过 PHP 调试连接发送。此选项仅在 PHP 3 中可用
3 − 错误将添加到文件目标字符串中
destination − 取决于如上所述的 message_type 参数。
extra_headers −当 message_type 参数设置为 1 时,将使用额外的标头。此消息类型使用与 mail() 相同的内部函数。
返回
error_log() 函数在成功时返回 TRUE,在失败时返回 FALSE。
示例
下面是 结论 −
<?php
error_log("That's no good!", 3, "/var/tmp/my-errors.log");
?>
文本将保存在日志中。

