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.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
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) andlog_errors=1
:The bytes sent to
error_log
will be:Next, test the same code with
log_errors_max_len=4
andlog_errors=1
. (Remember to restart the server.)error_log
will now be:(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 bylog_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 usinglog_errors_max_len=4
,display_errors=1
,html_errors=0
,error_prepend_string="PPPP"
, anderror_append_string="AAAA"
. The output sent to the client is:Now run the same code using
log_errors_max_len=4
,display_errors=1
,html_errors=1
,error_prepend_string="PPPP"
, anderror_append_string="AAAA"
. (error_prepend_string
anderror_append_string
apply only to displayed errors, not logged errors.) The output sent to the client is: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.)
Verified Pascal's initial thought:
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.