log_errors_max_len = 1024 in php.ini, but php log keeps growing

╄→гoц情女王★ 提交于 2020-01-10 04:54:06

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.)



来源:https://stackoverflow.com/questions/1966540/log-errors-max-len-1024-in-php-ini-but-php-log-keeps-growing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!