Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6053073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:59:54+00:00 2026-05-23T07:59:54+00:00

Can anyone explain why I am receiving the following error? In the code, if

  • 0

Can anyone explain why I am receiving the following error?

In the code, if the echo $gz; is commented out I receive no error (but also no output!), if it isn’t I get (from Firefox),

Content Encoding Error


The page you
are trying to view cannot be shown
because it uses an invalid or
unsupported form of compression.


Thanks for your help, here’s the code:

ob_start('ob_gzhandler') OR ob_start();
echo 'eh?';
$gz = ob_get_clean();
echo $gz;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:59:55+00:00Added an answer on May 23, 2026 at 7:59 am

    The output of your application should only contain one output encoding. If you have multiple chunks that are encoded differently, then the browser will get a result that it is impossible to work with. Hence the encoding error.

    Kohana itself makes already use of the output buffer. If you want to combine that with your ob_gzhandler output buffer, you need to start your buffer before kohana initialized it’s own. That’s because output buffer are stackable. When kohana has finished it’s output buffering, yours will apply:

    ob_start('ob_gzhandler'); # your buffer:
       ob_starts and ends by kohana
    

    So whenever kohana has done some output, these chunks will get passed on into your output callback (ob_gzhandler()) and will be gz-encoded.

    The browser should then only get gz-encoded data as it was the output buffer at the topmost level.

    Using ob_gzhandler and manually echo’ing the buffer

    If you make use of ob_start('ob_gzhandler') to let PHP deal with the compression and you then echo ob_get_clean(), you will create an unreliable output. That’s related to how the compression togther with output buffering works:

    PHP will buffer chunks of output. That means, PHP starts to compress the output but keeps some bytes to continue compressing. So ob_get_clean() returns the so-far compressed part of the buffer. Often that result is not complete.

    To deal with that, flush the buffer first:

    ob_start('ob_gzhandler') OR ob_start();
    echo 'eh?';
    ob_flush();
    $gz = ob_get_clean();
    echo $gz;
    

    And ensure you don’t have any more output after that.

    If you would have PHP reached the end of your script, it would have taken care of that: Flushing and outputting.

    Now you need to manually call ob_flush() to explicitly make PHP push the buffer through the callbacks.

    Inspecting HTTP Compression Problems with Curl

    As firefox will return an error, another tool to inspect what’s causing the encoding error is needed. You can use curl to track what’s going on:

    curl --compress -i URL
    

    Will request the URL with compression enabled while displaying all response headers and the body unencoded. This is necessary as PHP transparently enables / disables compression of the ob_gzhandler callback based on request headers.

    A response also shows that PHP will set the needed response headers as well. So no need to specify them manually. That would be even dangerously, because only by calling ob_start('ob_gzhandler') you can not say if compression is enabled or not.

    In case the compression is broken, curl will give an error description but would not display the body.

    Following is such a curl error message provoked with an incompletely generated output by a faulty php script:

    HTTP/1.1 200 OK
    X-Powered-By: PHP/5.3.6
    Content-Encoding: gzip
    ...
    
    curl: (23) Error while processing content unencoding: invalid code lengths set
    

    By adding the --raw switch, you can even peak into the raw response body:

    curl --compress --raw -i URL
    

    That can give an impression what’s going wrong, like uncompressed parts within the body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone explain why following code won't compile? At least on g++ 4.2.4. And
Can anyone explain to me what the following line of C# code does? public
Can anyone explain why this code gives the error: error C2039: 'RT' : is
Can anyone explain why I get the following errors when compiling the code shown
I'm using the code below and receiving the FileNotFound exception. Can anyone explain why
Can anyone explain to me what does the following Ruby code do? VARIABLE.scan /\((.+)\)$/
Can anyone explain the following immediate window behavior: Debug.Print mDb.DatabaseOptions Method arguments must be
can anyone explain me what happen here?? i have this html code: <div class=calculadora>
Can anyone explain why the following script behaves differently on two different platforms? Script:
Can anyone explain how javascript trackers (like the code that Google Analytics and Click,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.