Page 1 of 1

Error: output on closed stream while sending to client (blank PHP pages)

Posted: Thu Nov 26, 2026 9:54 am
by myVesta
In some situations, visitors may randomly receive a completely blank page instead of the expected website content, even though the HTTP response status is 200 OK.

At the same time, the following error appears in the nginx error log:

Code: Select all

output on closed stream while sending to client
This issue has been observed on servers running nginx as a reverse proxy in front of Apache2 with PHP-FPM, particularly with nginx 1.18.0 and PHP 7.3.

The issue appears to be related to PHP scripts generating a large number of warnings, notices or other error messages that are being transferred to Apache through the FastCGI protocol.

Under certain circumstances, this may cause premature termination of the response stream. Apache may send a response with Content-Length: 0, followed by the actual HTML content, causing nginx to attempt to send data to an already closed HTTP/2 stream.

Solution:

Edit the PHP-FPM pool configuration file for the affected domain:

Code: Select all

/etc/php/X.X/fpm/pool.d/YOURDOMAIN.COM.conf
Add the following three lines (or modify the existing directives if they are already defined):

Code: Select all

php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php-site-errors/YOURDOMAIN.COM.log
Create the directory and the PHP error log file:

Code: Select all

mkdir -p /var/log/php-site-errors
touch /var/log/php-site-errors/YOURDOMAIN.COM.log
chown USERNAME:USERNAME /var/log/php-site-errors/YOURDOMAIN.COM.log
chmod 600 /var/log/php-site-errors/YOURDOMAIN.COM.log
Replace USERNAME with the hosting account username, YOURDOMAIN.COM with the actual domain name, and X.X with the PHP version used by the website.

Make sure that the PHP-FPM pool user has write access to the log file and that the path is permitted by open_basedir, if applicable.

Restart PHP-FPM to apply the new settings:

Code: Select all

systemctl restart phpX.X-fpm
This workaround redirects PHP error messages directly to a dedicated log file instead of sending them to Apache through the FastCGI protocol.

Unlike disabling PHP error reporting entirely, this solution allows you to keep PHP error logging enabled and continue debugging your PHP application.

Important: The dedicated PHP error log may grow very quickly if the application generates a large number of warnings. Make sure to configure log rotation and investigate the underlying PHP warnings.

This solution has been successfully tested on a production server where hundreds of these nginx errors had previously occurred. After applying the workaround, no further occurrences were observed during 13 hours of monitoring.

Possibly related PHP bugs:

https://bugs.php.net/bug.php?id=72185
https://bugs.php.net/bug.php?id=81589

Related myVesta Knowledge Base article:

Error: Zlib error -2 deflating data ((null))