Home  >  Q&A  >  body text

Log line limit for writing to Apache Errorlog from mod php error_log

I have a simple apache 2.4 mod_php setup as the web server. The error_log directive in php.ini is not set, so it takes the default value of 0. The behavior is described here (https://www.php.net/manual/en/function.error-log.php) and to summarize the end result, I see that it is forwarded to the SAPI (mod_php) module Log handler. The logs are forwarded to Apache for processing, which in turn logs them to a file based on the ErrorLog directive I set.

Now the problem is that when the log statements on the php side are longer than 8192 bytes, they are truncated to a string of exactly 8192 bytes, as shown in the Apache error log. The 8192 bytes limit is a bit confusing, so when attaching strace to the worker thread and looking at the system calls, I found that it only does a single write call with 8192 bytes as the length to write. I know php has log limit controls/directives but they don't have any effect on the error_log statement, I verified this too. Just to add, my current php log length limit is 1024 (default) but it still logs 8192 bytes in the apache error log.

Comparing this behavior to sending the error_log to a file with parameter message_type of 3, I can see that the complete string is written in chunks of 8192 bytes. Attached is the strace log for this:

fstat(64, {st_mode=S_IFREG|0777, st_size=25009583, ...}) = 0
lseek(64, 0, SEEK_CUR)                  = 0
lseek(64, 0, SEEK_CUR)                  = 0
write(64, "<text to be logged>"..., 8192) = 8192
write(64, "<continued text ...>"..., 8192) = 8192
write(64, "<continued text ...>"..., 8192) = 8192

If message_type is 0, the only difference is that there is only one write call.

Can someone provide some explanation on this and how to get around this 8192 byte limit?

P粉814160988P粉814160988282 days ago404

reply all(1)I'll reply

  • P粉567281015

    P粉5672810152024-02-04 10:50:33

    As already mentioned, please check twice

    log_errors_max_len should be 0.

    https://www .php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len

    As mentioned in the manual, this all happens in bytes, so we have to check other files. https://www.php.net/manual/ en/faq.using.php#faq.using.shorthandbytes

    nginx/php-fpm also needs to be adjusted:

    https://forums.freebsd.org/threads/howto-stop-nginx-php-fpm-from-truncating-your-stack-trace-error-message.56543/

    In /etc/php-fpm.conf, you can change the value of log_limit = NumberInBytes and then restart php-fpm

    To avoid or check for other errors, you can also Unset the error_log directive in php.ini to log it to nginx's standard error will then log into his own error log.

    Settings are also useful php-fpm configure catch_workers_output = yes in php-fpm.conf This way standard error is not discarded.

    reply
    0
  • Cancelreply