提问人:Brett 提问时间:2/27/2019 最后编辑:Brett 更新时间:3/13/2019 访问量:4782
PHP 7.3 未创建/写入错误日志文件
PHP 7.3 not creating/writing to error log file
问:
我刚刚升级到 PHP 7.3(使用 XAMPP),由于某种原因,它似乎没有将错误写入指定的日志文件。
我在页面输出中收到已弃用的错误,但它们似乎没有出现在任何日志文件中 - 这更理想,因为错误并不总是在页面显示中可见,例如,如果它们在属性值之间生成,它们就会隐藏在代码中。
在我的我有:php.ini
error_reporting = E_ALL
display_errors=On
display_startup_errors=On
log_errors=On
log_errors_max_len = 2048
ignore_repeated_errors=Off
ignore_repeated_source=Off
report_memleaks=On
report_memleaks=On
html_errors=On
error_log="C:\xampp\php\logs\php_error_log"
编辑:我今天刚刚注意到该文件是最近创建的,它在那里还有其他错误(由php.ini本身的问题生成的错误,例如已弃用的设置),但仍然没有记录任何有关页面本身引起的问题的信息。track_errors
编辑2:我创建了一个单独的脚本来故意生成错误,但它们似乎没有很好地记录,所以我不确定这些其他脚本是如何不记录的。
为什么我没有从页面记录错误?
答:
请试试这个
<?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, "[email protected]");
}
?>
定义和用法
error_log() 函数将错误消息发送到日志、文件或邮件 帐户。
语法
error_log(message,type,destination,headers);
**> 参数说明消息 必需。将错误消息指定为
日志类型:可选。指定错误消息的去向。
可能的值:0 - 默认值。消息被发送到 PHP 的系统记录器,
使用操作系统的系统日志记录机制或文件,具体取决于什么
error_log配置设置为php.ini 1 - 发送消息
通过电子邮件发送到目标参数 2 中的地址 - 不再在
use(仅在 PHP 3 中可用) 3 - 将消息附加到文件中
在目标 4 中指定 - 消息直接发送到 SAPI
logging handler destination 可选。指定
错误信息。此值取决于类型参数的值
headers 可选。仅当 type 参数设置为 1 时才使用。
指定其他标头,如 From、CC 和 Bcc。 多个标头
应用 CRLF (\r\n) 分隔 技术细节返回
值:成功时为 TRUE,失败时为 FALSE PHP版本:4.0+ PHP
更新日志: PHP 5.2.7:在类型参数中添加了值 4**
评论
php.ini
.ini
<?php phpinfo();