Jump to content
thunderousity

gzip ob_gzhandler cannot be used twice

Recommended Posts

In a bid to make my site faster I thought I would do as the site tests suggest and implement gzip page compression.

I have checked to see that gzip is enabled. Check.

I have added the following code to my .htaccess file. (I also tried the AddOutputFilterByType DEFLATE text/plain but that didn't seem to work, which may be down to the fact that I hadn't added <? ob_start("ob_gzhandler"); ?> at that time)

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>

Added this code in my php: <? ob_start("ob_gzhandler"); ?>

However I get the following error:

ob_start(): failed to create buffer in /somefolder/anotherfolder on line 2, referer: https://www.google.com/
...mod_fcgid: stderr: PHP Warning:  ob_start(): output handler 'ob_gzhandler' cannot be used twice...

Took me ages to find the fact that I needed the <? ob_start("ob_gzhandler"); ?> in my pages. Annoyingly, most sites tell you to just add the mod_gzip code to .htaccess file.

Any ideas?

Edited by thunderousity
grammar

Share this post


Link to post
Share on other sites

You don't need both, in fact it might cause problems if you compress the data twice.  Just let the web server do it, there's no need to use PHP for that.  Just make sure PHP is using the correct MIME type.

Share this post


Link to post
Share on other sites

Ah ok - Done a bit more reading. I thought the ob_gzhandler indicated to the server to run gzip for that page.

I have removed both the mod_gzip text from the .htaccess file and the ob_gz_handler part from the page.

I removed the mod_gzip text from the .htaccess file as it still wasn't compressing according to whatsmyip gzip test

I added the following Deflate text to the .htaccess file instead to see if this would work but still no compression.  

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Using Chrome dev tools I checked the response headers and there is no content-encoding being returned despite Accept- encoding being present in the request header section and returning 'gzip, deflate'.

Edited by thunderousity
Formatting

Share this post


Link to post
Share on other sites

I would add the gzip stuff back to htaccess.  You want to enable that.  The server should negotiate with the browser to determine what to use, you wouldn't want the server to always use gzip if the browser didn't support it.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...