"ob_gzhandler" on the same server not always supported

4

On the same hosting server, some accounts support ob_gzhandler and send the page with compression for the browser:

/* Sending gz-encoded data to web browsers
 * that support compressed web pages
 */
ob_start("ob_gzhandler");

But other accounts with the code above fail and trigger the following error:

  

Content Encoding Error

     

The page you are trying to open may not be displayed because it uses an unsupported or invalid form of compaction.   Contact the site managers to let them know about this issue.

Question

How to discern the cause of the invalid encoding error?

Note: The PHP configuration for both domains is strictly the same as Apache directives.

    
asked by anonymous 24.02.2015 / 19:12

1 answer

1

For my particular case, the problem was in the definition of the page headers, where scripts with the problem of triggering the "Content Encoding" error, the headers were being defined after the opening of the buffer output:

ob_start("ob_gzhandler");

$expires = 2678400;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header('Content-Type: text/html; charset=ISO-8859-1');

To resolve, the headers have been set first, and the output buffer in second:

$expires = 2678400;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header('Content-Type: text/html; charset=ISO-8859-1');

ob_start("ob_gzhandler");

Since these are older projects (+4 years), it looks like something has changed in the latest versions of PHP, and the output buffer opening declaration can no longer come before the page.

    
25.02.2015 / 13:37