Keep in mind that mrfritz379's example (#49800) is just an example. You can achieve that example's result in a more efficient manner without using output buffering functions:
echo "<p>Search running. Please be patient. . .";
$output = "<p>FileList: </p>\n";
if (is_dir($dir)) {
$dh = opendir($dir);
while (($fd = readdir($dh)) != false) {
echo " .";
$output .= $fd;
}
}
echo "</br>Search Complete!</p>\n";
echo $output;
In addition to John Smith's comment (#42939), ob_gzhandler() may still set the HTTP header "Content-Encoding" to "gzip" or "deflate" even if you call ob_end_clean(). This will cause a problem in the following situation:
1. Call ob_gzhandler().
2. Echo "Some content";
3. Call ob_end_clean().
4. Echo "New content";
In the above case, the browser may receive the "Content-Encoding: gzip" HTTP header and attempts to decompress the uncompressed "New content". The browser will fail.
In the following situation, this behaviour will go unnoticed:
1. Call ob_gzhandler().
2. Echo "Some content";
3. Call ob_end_clean().
4. Call ob_gzhandler().
5. Echo "New content";
This is because the second ob_gzhandler() will mask the absence of the first ob_gzhandler().
A solution would be to write a wrapper, like John Smith did, for the ob_gzhandler().