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

后端 未结 3 1030
小鲜肉
小鲜肉 2020-12-20 14:05

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

3条回答
  •  独厮守ぢ
    2020-12-20 14:39

    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:

    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
    Notice: Unde in C:\index.php on line 5
    AAAAPPPP
    Notice: Unde in C:\index.php on line 5
    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.)

提交回复
热议问题