Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect when Apache mod_pagespeed is running #234

Open
raamdev opened this issue Jul 8, 2014 · 8 comments
Open

Detect when Apache mod_pagespeed is running #234

raamdev opened this issue Jul 8, 2014 · 8 comments

Comments

@raamdev
Copy link
Contributor

@raamdev raamdev commented Jul 8, 2014

Quick Cache should attempt to detect when Apache mod_pagespeed is running and generate an alert that Quick Cache source code notes might be removed if the Pagespeed Remove Comments filter is enabled.

Forked from #18 (comment).

@sous-studio
Copy link

@sous-studio sous-studio commented Jul 17, 2014

The easy way:

    function check_pagespeed1() {
        return in_array("mod_pagespeed", apache_get_modules());
    }

I believe the more correct way (due to some issues with PHP running as CGI not detected by apache_get_modules):

    function check_pagespeed2() {
        ob_start(); // Required due to PHPInfo output style
        phpinfo();
        $content = ob_get_contents();
        ob_end_clean(); 
        return strstr($content, "mod_pagespeed");
    }

Not sure if it helps. Actually, not sure who needs mod_pagespeed or Apache, since one is lazy admin scheme, while another is monster of 90's, so unless you're stuck with project that "requires" Apache, and/or loss of time for rewriting outweights possible benefit, I would discourage use of both.

@jaswrks
Copy link

@jaswrks jaswrks commented Jul 18, 2014

@raamdev I agree, apache_get_modules() is very unreliable, because most hosting companies will not run Apache as a DSO these days, it is run via CGI in most cases. Making apache_get_modules() difficult to rely on.

I tested the phpinfo() approach but this seems not to work. I think, because it is somewhat dependent upon the Apache configuration; i.e. whether to run in production mode with respect to the flags that Apache will reveal with ServerTokens.

Here are a couple other ways to check for Pagespeed that I just tested...

  1. See: https://developers.google.com/speed/pagespeed/module/faq#not-rewriting

    Using this to our advantage, we can run a periodic check with code like this.

    <?php
    $headers = get_headers(home_url('/'));
    if(isset($headers['X-Mod-Pagespeed']) || isset($headers['X-Page-Speed']))
        $running_pagespeed = TRUE; // Either in Apache or with Nginx.
  2. Or, if Quick Cache added this to the .htaccess file...

    <IfModule pagespeed_module>
      <IfModule rewrite_module>
          RewriteEngine on
          RewriteRule .* - [E=running_mod_pagespeed:1]
      </IfModule>
    </IfModule>
    
    <?php
    $running_mod_pagespeed = !empty($_SERVER['running_mod_pagespeed'])
        || !empty($_SERVER['REDIRECT_running_mod_pagespeed']);
@jaswrks
Copy link

@jaswrks jaswrks commented Jul 18, 2014

Reference article: https://www.digitalocean.com/community/tutorials/how-to-get-started-with-mod_pagespeed-with-apache-on-an-ubuntu-and-debian-cloud-server

Explains how to install Pagespeed on Ubuntu, in case you'd like to run a few tests.

@sous-studio
Copy link

@sous-studio sous-studio commented Jul 18, 2014

+1 Indeed, you approach seems better. The general idea here is to know whether to enable HTML Compressor? (No, in case of pagespeed?)

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Jul 21, 2014

@sous-studio @jaswsinc Thanks so much for jumping in here!

@jaswsinc I like the method of checking the headers. It seems a bit more reliable IMO, as the .htaccess method depends on the .htaccess file being successfully written and on the rewrite_module being active.

@sous-studio writes...

The general idea here is to know whether to enable HTML Compressor? (No, in case of pagespeed?)

This issue wasn't related to the HTML Compressor feature. We need to check for the presence of the Pagespeed module because one feature of that module involves stripping HTML comments from the source code, which would also strip out any HTML comments that Quick Cache adds. A site owner may see those Quick Cache notes missing and think that there's a problem with Quick Cache, when in fact there is no problem and it's just Pagespeed stripping the comments.

@jaswsinc Do you see any reason we should disable the HTML Compressor, or even mention something about the HTML Compressor, when Pagespeed is detected?

@jaswrks
Copy link

@jaswrks jaswrks commented Jul 21, 2014

Do you see any reason we should disable the HTML Compressor, or even mention something about the HTML Compressor, when Pagespeed is detected?

Quick Cache notes missing and think that there's a problem with Quick Cache, when in fact there is no problem and it's just Pagespeed stripping the comments.

Roger that :-) Well, if we are going to do a friendly note about Pagespeed and HTML comments, I think it might also be worth a little note in the HTML Compressor section of Quick Cache too. Not super important, but maybe something like...

"It seems you have Pagespeed installed on this server. NOTE: Pagespeed and the HTML Compressor both perform similar tasks. If you intend to keep Pagespeed, you probably don't need the HTML Compressor enabled also; i.e. there is a potential for a conflict if you enable them both; since both of these applications do much the same thing."

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Jul 21, 2014

I think it might also be worth a little note in the HTML Compressor section of Quick Cache too. Not super important, but maybe something like...

Will do. Thanks! :)

@raamdev
Copy link
Contributor Author

@raamdev raamdev commented Jun 3, 2016

Noting that a recent support issue was resolved by disabling mod_pagespeed; appeared to have some strange conflict with Comet Cache:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants