1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

This PHP line corrupted my Falcon caching at WordPress

Discussion in 'PHP' started by Jeffr2014, Feb 26, 2015.

  1. #1
    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(); ?>

     
    Solved! View solution.
    Jeffr2014, Feb 26, 2015 IP
  2. #2
    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):
     
    billzo, Feb 26, 2015 IP
  3. Jeffr2014

    Jeffr2014 Active Member

    Messages:
    254
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    55
    #3
    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 :(
     
    Jeffr2014, Feb 26, 2015 IP
  4. billzo

    billzo Well-Known Member

    Messages:
    961
    Likes Received:
    278
    Best Answers:
    15
    Trophy Points:
    113
    #4
    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.
     
    billzo, Feb 26, 2015 IP
    Jeffr2014 likes this.
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    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).
     
    PoPSiCLe, Feb 26, 2015 IP
  6. Jeffr2014

    Jeffr2014 Active Member

    Messages:
    254
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    55
    #6
    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
     
    Jeffr2014, Feb 26, 2015 IP