Results 1 to 2 of 2

Thread: PHP: Working around ob_gzhandler bug

  1. #1
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 23 Times in 23 Posts

    Default PHP: Working around ob_gzhandler bug

    I've just thought of a fairly obvious solution to the bug that causes output buffering to break when trying to clean a buffer that uses the ob_gzhandler compression handler.

    It's a bit crude perhaps; it works on the principle of using a top level buffer with gzhandler, then always using a nested 'plain' buffer for directly capturing output. This way, the plain buffers can always be cleaned, but the compression will still be applied when the script ends.

    At the begining of your script, start buffering with two buffers:
    PHP Code:
    ob_start('ob_gzhandler');
    ob_start(); 
    Then if you need to clean the buffers down to any that use ob_gzhandler, use something like this:
    PHP Code:
    $end=false;
    do {
        
    $status ob_get_status();
        if(
    $status['name'] == 'ob_gzhandler') {
            
    $end=true;
        } else {
            @
    ob_end_clean();
        }
    } while (!
    $end); 

  2. #2
    Join Date
    Mar 2005
    Location
    Isle of Man
    Posts
    1,261
    Thanks
    3
    Thanked 23 Times in 23 Posts

    Default

    A very important update to this. I've just noticed a glaring flaw that would enduce an infinite loop should for some reason a no ob_gzhandler is started.

    fix:
    PHP Code:
    $end=false;
    do {
        
    $status ob_get_status();
        if(@
    $status['name'] == 'ob_gzhandler') {
            
    $end=true;
        } else {
            if(!@
    ob_end_clean()) {
               
    $end=true;
            }
        }
    } while (!
    $end); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. cdosys not working
    By Andie in forum General Technical Support
    Replies: 2
    Last Post: 14th July 2006, 03:26 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •