'Limit of log line written to Apache Errorlog from mod php error_log
I have a simple setup of apache 2.4 + mod_php as web server. The error_log directive in php.ini is not set so it takes on the default value of 0. The behaviour is covered in this (https://www.php.net/manual/en/function.error-log.php), to summarise as an end result I see that it is forwarded to the SAPI (mod_php) module's logging handler. The logs are forwarded to Apache to handle it, which in turn logs in a file based on the ErrorLog directive I have setup.
The problem now is that when the log statements are longer than 8192 bytes on php end, they get truncated to exactly 8192 bytes string as seen in the Apache error logs.
The 8192 byte limit was a bit puzzling so on attaching strace to a worker and looking at the system calls, I see that it only does a single write call with 8192 bytes as the length to be written. I know that php has log limit controls/directives but they don't have any effect on error_log statements and I have verified that too. Just to add, my current log length limit is 1024(default) in php but it still logs 8192 bytes in apache error log.
Comparing this behaviour to sending the error_log to a file by using the parameter message_type as 3, I can see that the complete string is written in chunks of 8192 bytes. Attaching the strace logs 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
In case of message_type being 0, the only difference is that there's only one write call.
Can someone provide some explanation on this and how to bypass this 8192 bytes limit?
Solution 1:[1]
Awlays check twice, as already mentioned your
log_errors_max_len should be 0.
https://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors-max-len
As the manual mentions mentions, that`s all happening 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 need to be adjustet:
In your /etc/php-fpm.conf you can change the value of log_limit = NumberInBytes and than restart php-fpm
To avoid or check for other errors you could also unset error_log directive in your php.ini so that it log it to standard error which nginx will than log into his own error log.
It would also be usefull to set catch_workers_output = yes in your php-fpm configuration php-fpm.conf so that the standard error wont be discarded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Thorsten Wolske |