I activated WordFence caching for my blog and noticed that the pages were corrupted when served from cache. After hours of investigation I found the culprit. I had the following line as the first line in header.php file of my WP theme. It was added by a web developer (contractor from Elance) a while ago and it was causing page corruption with WordFence's Falcon cache and regular cache. Can anybody explain me what this line was doing and what are the consequences of removing it? <?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
It starts the ob_start output buffer and sets it to compress output if the browser supports it. The consequences of removing it depends on whether or not anything else in your code relies on it. Wordpress is not set up to buffer output like that. I cannot speak as to the other code that was written for you. Output compression should be done at the server level if possible (and you do have a VPS so you can do that). But--and here's the kicker--I don't know if you are using a caching plugin and what the caching plugin is doing. You can try commenting out that line and test your site to see how it works and if it works fine, just leave it commented out. <?php //if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?> Code (markup):
I checked Apache configuration on my VPS and "deflate" module is checked, so I assume output compression is enabled...? I am using WordFence Falcon caching on my sites, it typically reduces overall page load time but increases TTFB quite a bit
Are you using cPanel? If you are, there are settings for output compression. If you want to see if your server will compress content automatically, comment out that line as I suggested earlier. Then do a compression test here: gidnetwork.com/tools/gzip-test.php It will tell you whether or not your server has compression enabled. Compressing output is best for slow internet connections. Otherwise, it is not much noticeable if you are on broadband. The overhead required to compress output requires additional CPU resources that may not be worth. As for WordFence Falcon, only you can determine whether or not that is worthwhile. And again, you should really drop your obsession with the time to first byte stuff. Nobody is going to notice 1/10th of a second or less.
You don't say anything about what kind of corruption you're seeing while ob_start() is active. ob_start() enables output buffering, which, among other things allows PHP to modify header-info even if there's output to the browser before the header-call - it basically waits until all the code of the page is parsed before outputting it (to put it simply).
Thanks. I am using Plesk panel, I checked with gidnetwork (thanks for the link) and the results show that compression is fine: Web page compressed? Yes Compression type? gzip Size, Markup (bytes) 81,514 Size, Compressed (bytes)15,023 Compression %81.6