php.ini 中的 log_errors_max_len = 1024,但 php 日志不断增长

发布于 2024-08-16 07:35:28 字数 100 浏览 12 评论 0原文

正如标题所说,我已经设置了 php 错误日志的最大长度,但它似乎一直增长得远远大于 1024。我正在使用正确的 php.ini,我已经重新启动了 apache 等。 php日志是666。

As the title says, I've set the max length for the php error log, but it seems to keep growing much much larger than 1024. I am using the correct php.ini, I've restarted apache, etc. The permissions on the php log are 666.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

装迷糊 2024-08-23 07:35:28

正如 PHP 的典型情况一样,从配置设置的名称甚至 文档,但该指令适用于单个日志消息的长度,而不是整个日志文件的长度。

使用 logrotate 或类似的工具来完成您想要做的事情。

As is typical for PHP, it is not really obvious from the name of the configuration setting, or even the documentation, but this directive applies to the length of a single log message, not the length of the log file as a whole.

Use logrotate or a similar tool for what you are trying to do.

贩梦商人 2024-08-23 07:35:28

验证 Pascal 的初步想法

log_errors_max_len整数

设置log_errors的最大长度
以字节为单位。 error_log信息中
添加了有关来源的信息。默认
是 1024 和 0 允许不应用任何
最大长度。 这个长度是
应用于记录的错误,显示
错误以及 $php_errormsg。

使用整数,值为
以字节为单位。速记符号,
如本常见问题解答中所述,也可能是
使用过。

Verified Pascal's initial thought:

log_errors_max_len integer

Set the maximum length of log_errors
in bytes. In error_log information
about the source is added. The default
is 1024 and 0 allows to not apply any
maximum length at all. This length is
applied to logged errors, displayed
errors and also to $php_errormsg.
When
an integer is used, the value is
measured in bytes. Shorthand notation,
as described in this FAQ, may also be
used.

合久必婚 2024-08-23 07:35:28

手册没有说明的是 log_errors_max_len 仅指 到错误消息的“正文”。这意味着单行错误仍然会大于您在此处设置的长度。

为了进行演示,请使用 log_errors_max_len=00 表示无限制)和 log_errors=1

<?php
// Set your server to these settings:
// error_reporting=-1 
// date.timezone=utc ;to suppress the error message "It is not safe to rely on the system's timezone settings."...
echo$msg1; echo$msg2;

发送到error_log<的字节/a> 将是:

[15-Jul-2015 01:23:45 utc] PHP Notice:  Undefined variable: msg1 in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice:  Undefined variable: msg2 in C:\index.php on line 5
‏

接下来,使用 log_errors_max_len=4log_errors=1 测试相同的代码。 (请记住重新启动服务器。)error_log 现在将是:(

[15-Jul-2015 01:23:45 utc] PHP Notice:  Unde in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice:  Unde in C:\index.php on line 5
‏

请注意,您的错误消息前面带有“[15-Jul-2015 01:23:45 utc] PHP 注意:< /code>”并附加“in C:\index.php on line 1”,导致行长于 log_errors_max_len 设置的行。)

出现此问题不仅包含 error_log,还包含发送到客户端的服务器输出。为了进行演示,请使用 log_errors_max_len=4display_errors=1 运行上面相同的代码>html_errors=0error_prepend_string="PPPP"error_append_string="AAAA"。发送到客户端的输出为:

PPPP
Notice: Unde in C:\index.php on line 5
AAAAPPPP
Notice: Unde in C:\index.php on line 5
AAAA

现在使用 log_errors_max_len=4display_errors=1html_errors=1< /strong>、error_prepend_string="PPPP"error_append_string="AAAA"。 (error_prepend_stringerror_append_string 仅适用于显示的错误,而不适用于记录的错误。)发送到客户端的输出为:

PPPP<br />
<b>Notice</b>:  Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAAPPPP<br />
<b>Notice</b>:  Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAA

另请注意,上述测试将返回相同的结果,即使您使用ignore_repeated_errors=0。这表明在裁剪错误消息之前会考虑“重复错误”。

(您的结果可能会有所不同,具体取决于所使用的 SAPI。以上测试是在 win 8.1 上使用 php-5.6.7-Win32-VC11-x86 CLI 完成的。)

What the manual doesn't state is that log_errors_max_len refers only to the "body" of the error message. This means that a single line of error will still be greater than the length you set here.

To demonstrate, run this code using log_errors_max_len=0 (0 means unlimited) and log_errors=1:

<?php
// Set your server to these settings:
// error_reporting=-1 
// date.timezone=utc ;to suppress the error message "It is not safe to rely on the system's timezone settings."...
echo$msg1; echo$msg2;

The bytes sent to error_log will be:

[15-Jul-2015 01:23:45 utc] PHP Notice:  Undefined variable: msg1 in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice:  Undefined variable: msg2 in C:\index.php on line 5
‏

Next, test the same code with log_errors_max_len=4 and log_errors=1. (Remember to restart the server.) error_log will now be:

[15-Jul-2015 01:23:45 utc] PHP Notice:  Unde in C:\index.php on line 5
[15-Jul-2015 01:23:45 utc] PHP Notice:  Unde in C:\index.php on line 5
‏

(Notice that your error message is prepended with "[15-Jul-2015 01:23:45 utc] PHP Notice:" and appended with "in C:\index.php on line 1", resulting in a line longer than what is set by log_errors_max_len.)

This issue occurs not just with error_log, but also with the server output sent to the client. To demonstrate, run the same code above using log_errors_max_len=4, display_errors=1, html_errors=0, error_prepend_string="PPPP", and error_append_string="AAAA". The output sent to the client is:

PPPP
Notice: Unde in C:\index.php on line 5
AAAAPPPP
Notice: Unde in C:\index.php on line 5
AAAA

Now run the same code using log_errors_max_len=4, display_errors=1, html_errors=1, error_prepend_string="PPPP", and error_append_string="AAAA". (error_prepend_string and error_append_string apply only to displayed errors, not logged errors.) The output sent to the client is:

PPPP<br />
<b>Notice</b>:  Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAAPPPP<br />
<b>Notice</b>:  Unde in <b>C:\index.php</b> on line <b>5</b><br />
AAAA

Also note that the above tests would return the same results even if you use ignore_repeated_errors=0. This shows that "repeated errors" are considered before the error messages are cropped.

(Your results may differ depending on the SAPI used. Above tests are done using php-5.6.7-Win32-VC11-x86 CLI on win 8.1.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文