Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in

Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Decoding the ob_end_flush() zlib Compression Notice

You are likely familiar with the frustration of seeing a warning log on your production server that simply does not appear in your local development environment:

Notice: ob_end_flush(): failed to send buffer of zlib output compression (1)

This error specifically targets the interaction between PHP's output buffering and Apache's mod_deflate module. The fact that your localhost works fine is the first clue; it means your application logic is sound, but the server environment differs in a critical way: production often runs with gzip compression enabled to save bandwidth, while local development usually does not.

How the Buffering Stack Works

To understand why ob_end_flush() fails here, you have to look at the order of operations and which layer owns the data. When you include view.php inside a block started by ob_start(), PHP captures that output into a buffer. You then extract it with ob_get_contents() and clear the buffer using ob_end_clean().

At this specific moment, your internal buffer is empty. The script continues to execute, eventually including master.php, which presumably outputs headers, footers, or other HTML content directly to the output stream. When you call ob_end_flush() after master.php has finished rendering, PHP attempts to send whatever data exists in its current buffer to the client.

The problem arises when Apache's mod_deflate is active on your server but not on your local machine (like XAMPP or MAMP). If mod_deflate is enabled, Apache expects to handle the compression of the final HTTP response. However, if PHP thinks it still has data in its buffer that needs flushing, and Apache tries to compress that output simultaneously, a conflict occurs. Because your internal buffer was cleaned (ob_end_clean()), there is no uncompressed data for PHP to flush. Apache, expecting a buffer to manage or seeing the compression mismatch, triggers the notice regarding zlib output compression failure.

Diagnosing the Environment Mismatch

The root cause is almost certainly the difference in server configuration. On your localhost, mod_deflate is likely disabled or not installed, so ob_end_flush() simply sends the (empty) buffer without issue. On your live server, mod_deflate is active. When Apache sees a request with compression enabled, it interacts differently with the output stream if PHP has manipulated the buffers aggressively.

If you check your server's .htaccess file or Nginx configuration, you will likely find lines similar to:

AddOutputFilterByType DEFLATE text/html

or

gzip on;

When these are active, the HTTP response header Content-Encoding: gzip is set. PHP's output buffering layer gets confused if it tries to flush an empty buffer while the web server expects to compress the payload.

Resolving the Conflict

The most robust solution is to ensure that your manual output manipulation does not interfere with Apache's compression logic. Since you are using ob_end_clean() to clear the buffer before including master.php, you effectively tell PHP, "I am done capturing output; stop buffering for me." However, calling ob_end_flush() afterward is redundant and dangerous in this context because it implies there is data to flush that isn't there.

You should remove the final ob_end_flush() call entirely if you have already cleaned the buffer. The sequence should look like this:

<?php
ob_start();
include 'view.php';

$data = ob_get_contents();
ob_end_clean(); // Buffer is now empty, but still technically "active" in some contexts until disabled/flushed

include 'master.php';

// Do NOT call ob_end_flush() here if the buffer was cleaned.
// The data from master.php is already on the output stream.
// If you need to disable buffering for subsequent requests, use:
ob_end_clean(); 
?>

Alternatively, if master.php relies on its own internal buffering logic that expects a flush, ensure that master.php handles its own buffer cleanup or disabling before returning control to the main script. A common pattern to avoid this specific notice is to disable output buffering entirely for the specific request if compression is handled strictly by the web server:

<?php
ob_start();
include 'view.php';
$data = ob_get_contents();
ob_end_clean();

// Disable PHP's internal buffering to let Apache handle it cleanly
if (function_exists('ob_end_flush')) {
    ob_end_flush(); 
} else {
    // Fallback if already ended or not needed
}

include 'master.php';

// Ensure no further buffering interferes
ob_end_clean();
?>

In practice, the cleanest approach is often to stop manually managing output buffers for the entire request lifecycle unless you have a specific reason to capture fragments. Relying on mod_deflate or Nginx gzip handles the compression transparently without PHP needing to know about it, provided you avoid mixing manual flushes with web server compression filters.

If you must keep your current structure, simply removing the final ob_end_flush() line usually resolves the notice immediately, as the buffer is already empty and awaiting transmission by Apache's compression layer.

Our network