thunderousity Posted November 6, 2018 Share Posted November 6, 2018 (edited) 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 November 6, 2018 by thunderousity grammar Link to comment Share on other sites More sharing options...
justsomeguy Posted November 6, 2018 Share Posted November 6, 2018 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. Link to comment Share on other sites More sharing options...
thunderousity Posted November 7, 2018 Author Share Posted November 7, 2018 (edited) 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 November 7, 2018 by thunderousity Formatting Link to comment Share on other sites More sharing options...
justsomeguy Posted November 7, 2018 Share Posted November 7, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now