PHP Bulletin Board Home
News About Home
Features of phpBB Test drive phpBB Downloads Support for phpBB The phpBB Community Styles for customising phpBB 3rd party modifications to phpBB

Support Home | Knowledge Base Home | Submit Article | Search Articles | Browse Articles
 Warning: (null)() [ref.outcontrol]: output handler 'ob_gzhandler' 
Description: Fix to enable the use of gzip on PHP 4.3.x servers
Author: JadeDragon
Date: Wed Aug 20, 2003 12:12 am
Type: Fix
Keywords: Warning: (null)() [ref.outcontrol]: output handler 'ob_gzhandler'
Category: Improvements
The Error:

Code:
Warning: (null)() [ref.outcontrol]: output handler 'ob_gzhandler'


The Fix.

Open the file /includes/page_header.php

Find this code



Code:

//
// gzip_compression
//
$do_gzip_compress = FALSE;
if ( $board_config['gzip_compress'] )
{
   $phpver = phpversion();

   $useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;

   if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
   {
      if ( extension_loaded('zlib') )
      {
         ob_start('ob_gzhandler');
      }
   }
   else if ( $phpver > '4.0' )
   {
      if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
      {
         if ( extension_loaded('zlib') )
         {
            $do_gzip_compress = TRUE;
            ob_start();
            ob_implicit_flush(0);

            header('Content-Encoding: gzip');
         }
      }
   }
}


And replace with this code

Code:
//
// gzip_compression
//
$do_gzip_compress = FALSE;
if ( $board_config['gzip_compress'] )
{
   $phpver = phpversion();

   $useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;

   if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) )
   {
      if ( extension_loaded('zlib') )
      {
         ob_end_clean();
         ob_start('ob_gzhandler');
      }
   }
   else if ( $phpver > '4.0' )
   {
      if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') )
      {
         if ( extension_loaded('zlib') )
         {
            $do_gzip_compress = TRUE;
            ob_start();
            ob_implicit_flush(0);

            header('Content-Encoding: gzip');
         }
      }
   }
}


The tech on why.
Quote:

PHP 4.3.x handles code a bit tighter than the previous versions which is good overall. If the php.ini the output_buffering is set to "On" it makes sure all coding is validated within the headers. The headers cannot be called from outside the head tags and prevents the headers being rewritten by coding out side of the head tags. This is a good thing to have, but previously coded applications which did not validate the headers (because it was not required) will have problems.

The error occures because the headers are being called more than once and it is not clearing out the ob_start ('gzhandler'); . The gzhandler compresses your pages for faster delivery from the server. (Gzip)

The ob_end_clean() ends the previous compression cycle (cleans the output buffering) and ob_start("ob_gzhandler") starts the cycle again for the new page.



Other Information:

PHP does not automatically compress your files to output.

Enabling Zlib through the php.ini (or having your host enable it for you) compresses your files on a global scale. Zlib may or may not be available from your host. Zlib compression is generally prefered, but may cause problems with other applications relying on GZip which do not have the IF/Else statement for Zlib OR gzip.

Gzip is a script based function and supported by most hosts.

This is an either or situation as you can not use both for compression


by JadeaDragon

Username: Password:
News | Features | Demo | Downloads | Support | Community | Styles | Mods | Links | Merchandise | About | Home
 © Copyright 2002 The phpBB Group.