Ph: +4930868706504

WP-Cache 2.1 revisited: Compression

Posted on February 11th, 2007 by Reiner.
Categories: English, Computers.

Speeding up WordPress appears to be the play of the month, see 5 Ways to Speed Up Your Site. I ran into an interesting post from Nick Georgakis in which he presents both an in-depth discussion and working code to properly enable compression with WP-Cache. The main idea is, that in order to support compression, WP-Cache must keep compressed cached files separate from uncompressed ones. This is achieved by appending the compression method to the url when allocating and retrieving cache entries. That way, browsers will always be returned a version of the content they will be able to handle - depending on whether they requested compressed contents or not in the first place. 

I’ve adopted Nick’s code to the current 2.1 version of the WP-Cache and applied some minor amendments, e.g. replaced the somewhat complicated gzcompress call with the more up-to-date gzencode. Be warned though, that it requires at least PHP 4.2.

My WP-Cache 2.1 as is (including a Windows hack for wp-cache.php inspired by Nick Georgakis): wp-cache-21-compression.zip [updated to include How to prevent WP-Cache from changing a Feed’s Content-Type to text/html] Changes from WP-Cache 2.1 to my version: wp-cache-phase1.htm and wp-cache-phase2.htm

What it comes down to: WP-Cache is a very effective plugin that lets WordPress serve content just as if it were plain static html. Why not have WP-Cache take a snapshot of the compressed image as well?

20 comments.

Kelson

Comment on February 13th, 2007.

There is an alternate solution, though it requires you to either have access to the server config or be able to convince your admin to make the change: turn compression off in WordPress and enable it in the web server itself. (Apache would use mod_gzip or mod_compress.) All the PHP and caching works on the original, uncompressed files, and compressed files still get sent to the browsers that want it. Even better, it will also compress any static or otherwise non-WordPress files you have on your site.

Reiner

Comment on February 18th, 2007.

Yes, but the compression will occur on each and every access, which might be considered a waste of resources. As WP-Cache basically just takes a snapshot of a page, why not let WP-Cache take the snapshot from the data which already have been compressed?

Reiner Saddey’s Place » WP-Cache 2.1 revisited: Have x-gzip and gzip compression share same cache slot

Pingback on April 10th, 2007.

[…] modified case that causes excessive traffic for RSS feeds, I encountered a mild weakness within the compression code, that causes both gzip and x-gzip variants of a particular page to use separate cache slots (i.e. […]

Speed Up Sites with htaccess Caching

Pingback on May 29th, 2007.

[…] WP-Cache 2.1 revisited: Compression […]

Chris

Comment on July 4th, 2007.

Thanks for the plugin, I do have a question though - is it known to work with WordPress 2.2.1? I’m trying it out on both a MAMP installation and a hosted installation of WP 2.2.1 and neither works, the WP compression is disabled (options > Reading), symlinks are properly set up and define(’WP_CACHE’, true); is in the wp-config.php file.

The gzip is being created just fine, but it’s being displayed in the browser on subsequent refreshes (the gibberish referred to above), tried with several browsers, making sure the browser cache was refreshed every time.

Downloading the .gz files to my computer and then unzipping proves them to be okay, so I’m at a bit of a loss, I am currently unable to post the URL as the site is still in development…

Reiner

Comment on July 5th, 2007.

Gibberish: As of WP 2.2.1 and WP-Cache, no, I still have to upgrade to 2.2.1. The symptoms you describe suggest that there’s a problem with the http headers that might be tracked down with http://www.blunck.se/iehttpheaders/iehttpheaders.html Anyway, I’ll try to install WP 2.2.1 this WE and see whether there are quirks specific to this version.

HitHimAgain

Comment on July 19th, 2007.

Having the same problem as Chris. WP 2.2.1 causes the result to be garbled. It’s definitely a problem with the header, as I was watching the request in firebug - content type is still chunked, not gzip.

links for 2007-07-22 at orioa

Pingback on July 22nd, 2007.

[…] Reiner Saddey’s Place » WP-Cache 2.1 revisited: Compression WP-Cache ã§gzip共存ファイルをé…布ã•れã¦ã„る。 (tags: wordpress plugin gzip) […]

Dave

Comment on July 25th, 2007.

Anyone have any luck with the Gibberish gzip output in 2.2.1?

Reiner

Comment on July 25th, 2007.

Gibberish: Well, I’m a little bit at a loss as to what might cause this. I upgraded from WP 2.1 to 2.2.1, step by step, and did not encounter any problem with WP-Cache.

The Widgets plugin was no longer required, as it is now included within the core.

I replaced Spam Karma with its most recent version and made sure, that the extra Spam Karma WP-Cache plugin was installed (it calls WP-Cache to purge cache entries for posts that have comments added).

I played some time with the new Vistered Little 1.7.5, but then reverted to an old 1.6 one, because the new one heavilly relies on server side processing that would require modifications to WP-Cache.

Eventually, I re-enabled WP-Cache (with all its files untouched) and it continued to work just as well (or as bad) as before and no gibberish at all (with both WP standard theme and Vistered Little as well). Is there a web site available that demonstrates the problem? There are some spots within WP-Cache around the code that outputs its cached data that I consider problematic. The only sure way to cause a mismatch of header and data I can think of, is to enable compression either within WordPress or Apache. I’ll check on that right now.

I’m currently working on an enhancement to WP-Cache and some potential fixes as well (that’s the reason this blog might not use WP-Cache right now). But progress is slow, as my employer still keeps me quite busy.

Hit Him Again

Comment on July 26th, 2007.

Well I appreciate your work toward fixing the problem. I would love to be able to demonstrate the bug for you, but it would require my having the site down. I look forward to whatever you can do.

Dave

Comment on July 26th, 2007.

I’d be happy to put my site into broken mode. Just shoot me an email. Also I’ve uploaded my mod version to the server, just in case that is what’s breaking it. http://rag.nu/2.1.1.mod.wp-cache.tar

Nick Georgakis

Comment on August 13th, 2007.

I believe I have found the cause of the gzip “gibberish” bug. As Reiner correctly suspected this is caused by missing headers.
In some PHP installations wp_cache_ob_callback() is called BEFORE wp_cache_shutdown_callback() so any headers pushed in $wp_cache_meta_object->headers in wp_cache_ob_callback() are lost when $wp_cache_meta_object->headers is re-initialised … = array(); in wp_cache_shutdown_callback().
By commenting that line the loss is prevented.
See:
http://www.ngtech.gr/blog/en/programming/php/modifying-wp-cache-20-to-generate-and-cache-gzipped-output-once-and-serve-it-multiple-times-2006-10-22.html#comment-1468

Wp-cache e Gzip: ecco il plugin | Josie's blog

Pingback on September 10th, 2007.

[…] funzionare le modifiche), basato chiaramente sull’originale di Ricardo, che potete trovare qui. Avere tutte le pagine di Wordpress salvate in cache è un ottimo vantaggio, ma se è possibile […]

Smallvoid.com

Trackback on September 27th, 2007.

Activated gzip compression…

Discovered how to activate gzip compression for WP-Cache in IIS, so now the pages should be quicker to load.

Updated Internet Explorer Tip about how Reset Internet Explorer Settings can be used to remove branding for IE7.
Added Vista Netwok Tip abo…

WP-Cache + gzip without excessive CPU overhead, yay! | Tummblr

Pingback on November 4th, 2007.

[…] all credit goes to Nick Georgakis, who first came up with the idea and code, and Reiner Saddey, who cleaned up and improved on some of the code. My only contribution is merging the changes with […]

Improving WP Super Cache? gzip for logged in users | Tummblr

Pingback on November 6th, 2007.

[…] gzip enhanced - modified files WP Super Cache gzip enhanced - diffs Credit: Nick Georgakis and Reiner Saddey Social […]

Christoph Dollis

Comment on February 7th, 2008.

Hi Reiner,

This plugin is excellent. It did indeed create COMPRESSED cache files with WordPress 2.3.3. I’m impressed!

I’m confused on one point. Is it ALSO supposed to create uncompressed .html cache files beside the compressed ones… or just compressed files?

Finally, is there any advantage to upgrading this to WP-Cache 2.1.2 or no, not really?

Aha! I just typed the above, then saw Tummblr’s pingbacks where he claims to have done precisely that. Unfortunately, the download link for his code isn’t working so I’ll leave a comment for him there.

Otherwise, you, Nick… great code and thanks.

If anyone wants to drop by my blog, forget the business one where I have wp-cache/gzip enabled unless you’re into sales, marketing, and increasing your company’s profits. Instead, visit my personal blog where I can talk more about code, life, and such.

Have a great day all.

Christoph

Comment on February 7th, 2008.

Follow-up from my last comment/question: I think I get it.

Your script creates compressed cache files only because that’s all my browser asked for. However, if a browser asked for uncompressed files, it would create those. Makes sense.

I got your version to work fine, then got Tummblr’s version to work fine, and finally realized he pointed to a newer better version, WP-SuperCache available here and at the WordPress plugin repository here.

It’s got a handy control panel with options.

You guys have ALL done great optimization work. I have the above plugin working with WP 2.3.3 and it’s lickety split.

My one last question is…

… on my personal blog I use the WordPress theme switcher plugin which creates a wptheme cookie. Can your solution or any of the above solutions be used with caching and theme switcher?

Alessandro Ronchi

Comment on February 7th, 2008.

Is it possible to run wp-polls ajax widget with wp-cache?

Leave a comment

Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.





You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser