Version Description
Download this release
Release Info
| Developer | donncha |
| Plugin | |
| Version | 0.2 |
| Comparing to | |
| See all releases | |
Code changes from version 0.1 to 0.2
- readme.txt +159 -156
- wp-cache-phase1.php +14 -3
- wp-cache-phase2.php +35 -14
- wp-cache.php +19 -14
readme.txt
CHANGED
|
@@ -1,156 +1,159 @@
|
|
| 1 |
-
|
| 2 |
-
Contributors: donncha
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
in
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
RewriteCond %{
|
| 62 |
-
RewriteCond %{
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
RewriteCond %{
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
RewriteCond %{
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
RewriteCond %{
|
| 79 |
-
RewriteCond %{
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
RewriteCond %{
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
RewriteCond %{
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
RewriteCond %{
|
| 98 |
-
RewriteCond %{
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
RewriteCond %{
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
RewriteCond %{
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
RewriteCond %{
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
=== WP Super Cache ===
|
| 2 |
+
Contributors: donncha
|
| 3 |
+
Donate link: http://ocaoimh.ie/
|
| 4 |
+
Tags: performance,caching,wp-cache
|
| 5 |
+
Tested up to: 2.3.1
|
| 6 |
+
Stable Tag: 0.2
|
| 7 |
+
|
| 8 |
+
A modification of WP-Cache that produces static html files.
|
| 9 |
+
|
| 10 |
+
== Description ==
|
| 11 |
+
A modification of WP-Cache that produces static html files. After a html file
|
| 12 |
+
is generated your webserver will serve that file instead of processing the
|
| 13 |
+
comparatively heavier and more expensive WordPress PHP scripts.
|
| 14 |
+
It will only cache and serve files to users who are not logged in, who
|
| 15 |
+
have not left a comment on your blog, or who have viewed a password protected
|
| 16 |
+
post. That still probably leave 90% of your visitors who will benefit. The users
|
| 17 |
+
mentioned above will also benefit because your server won't be as busy as before.
|
| 18 |
+
This script should help your server cope with a front page appearance on digg.com
|
| 19 |
+
or other social networking site.
|
| 20 |
+
|
| 21 |
+
This plugin is a modified version of the WP-Cache 2 plugin by Ricardo Galli Granada.
|
| 22 |
+
His plugin is still available. We're standing on the shoulders of giants and benefiting
|
| 23 |
+
from the power of the GPL here. Thanks Ricardo for creating such a great plugin!
|
| 24 |
+
See the following URLs for more info on WP-Cache 2
|
| 25 |
+
|
| 26 |
+
1. http://mnm.uib.es/gallir/wp-cache-2/
|
| 27 |
+
2. http://wordpress.org/extend/plugins/wp-cache/
|
| 28 |
+
|
| 29 |
+
A classic method of preparing an underpowered site for a Digg frontpage appearance
|
| 30 |
+
or a Slashdotting has been to manually save copies of dynamically generated pages,
|
| 31 |
+
and place them in directories that match the permalinks structure.
|
| 32 |
+
|
| 33 |
+
This method of performance enhancement does help servers handle a higher load
|
| 34 |
+
without crashing, but is only effective when an oncoming rush of traffic can be
|
| 35 |
+
anticipated.
|
| 36 |
+
|
| 37 |
+
WP-Cache alone, while helpful, is not adequate in many cases, so this modification
|
| 38 |
+
was created to effectively mimic the manual page caching method, but to handle it
|
| 39 |
+
in an automated fashion.
|
| 40 |
+
|
| 41 |
+
Original WP-Cache by Ricardo Galli Granada, http://mnm.uib.es/gallir/
|
| 42 |
+
WP Super Cache by Donncha O Caoimh, http://ocaoimh.ie/
|
| 43 |
+
|
| 44 |
+
== Installation ==
|
| 45 |
+
1. You must have fancy permalinks enabled for this to work.
|
| 46 |
+
2. If you have WP-Cache installed already, please disable it. Edit wp-config.php
|
| 47 |
+
and make sure the WP_CACHE define is deleted, and remove the file
|
| 48 |
+
wp-content/advanced-cache.php. These will be recreated when you install this
|
| 49 |
+
plugin.
|
| 50 |
+
3. Upload this directory to your plugins directory. It will create a
|
| 51 |
+
'wp-content/plugins/wp-super-cache/' directory.
|
| 52 |
+
4. If you are using WordPress MU you will need to install this in
|
| 53 |
+
'wp-content/mu-plugins/wp-super-cache/' and the file wp-cache.php
|
| 54 |
+
must be copied into the mu-plugins directory.
|
| 55 |
+
5. WordPress users should go to their Plugins page and activate "WP Super Cache".
|
| 56 |
+
6. Now go to Options->WP Super Cache and enable caching. If you see an error message
|
| 57 |
+
or a blank screen you may need to fix it. See the "FAQ" section later in this
|
| 58 |
+
readme for instructions.
|
| 59 |
+
7. Edit the .htaccess file in your root directory and add the following code:
|
| 60 |
+
|
| 61 |
+
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
| 62 |
+
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
| 63 |
+
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
| 64 |
+
RewriteCond %{HTTP:Accept-Encoding} gzip
|
| 65 |
+
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f
|
| 66 |
+
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]
|
| 67 |
+
|
| 68 |
+
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
| 69 |
+
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
| 70 |
+
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
| 71 |
+
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html -f
|
| 72 |
+
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html [L]
|
| 73 |
+
|
| 74 |
+
That code must be inserted above the standard WordPress rewrite rules.
|
| 75 |
+
If your blog isn't located at the root of your server, you must add that directory
|
| 76 |
+
to the rules. For example, if your blog is in the directory "/blog/":
|
| 77 |
+
|
| 78 |
+
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
| 79 |
+
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
| 80 |
+
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
| 81 |
+
RewriteCond %{HTTP:Accept-Encoding} gzip
|
| 82 |
+
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{HTTP_HOST}/blog/$1index.html.gz -f
|
| 83 |
+
RewriteRule ^(.*) /blog/wp-content/cache/supercache/%{HTTP_HOST}/blog/$1index.html.gz [L]
|
| 84 |
+
|
| 85 |
+
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
| 86 |
+
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
| 87 |
+
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
| 88 |
+
RewriteCond %{DOCUMENT_ROOT}/blog/wp-content/cache/supercache/%{HTTP_HOST}/blog/$1index.html -f
|
| 89 |
+
RewriteRule ^(.*) /blog/wp-content/cache/supercache/%{HTTP_HOST}/$1/blog/index.html [L]
|
| 90 |
+
|
| 91 |
+
Your .htaccess should look similar to this:
|
| 92 |
+
|
| 93 |
+
-----------------.htaccess-----------------
|
| 94 |
+
RewriteEngine On
|
| 95 |
+
RewriteBase /
|
| 96 |
+
|
| 97 |
+
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
| 98 |
+
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
| 99 |
+
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
| 100 |
+
RewriteCond %{HTTP:Accept-Encoding} gzip
|
| 101 |
+
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz -f
|
| 102 |
+
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html.gz [L]
|
| 103 |
+
|
| 104 |
+
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
|
| 105 |
+
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$
|
| 106 |
+
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
|
| 107 |
+
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1index.html -f
|
| 108 |
+
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1index.html [L]
|
| 109 |
+
|
| 110 |
+
RewriteCond %{REQUEST_FILENAME} !-f
|
| 111 |
+
RewriteCond %{REQUEST_FILENAME} !-d
|
| 112 |
+
RewriteRule . /index.php [L]
|
| 113 |
+
-----------------.htaccess-----------------
|
| 114 |
+
|
| 115 |
+
== Frequently Asked Questions ==
|
| 116 |
+
If things don't work when you installed the plugin here are a few things to check:
|
| 117 |
+
1. Is wp-content writable by the web server?
|
| 118 |
+
2. Is there a wp-content/wp-cache-config.php ? If not, copy the file
|
| 119 |
+
wp-super-cache/wp-cache-config-sample.php to wp-content/wp-cache-config.php
|
| 120 |
+
and make sure WPCACHEHOME points at the right place. "plugins" should be
|
| 121 |
+
"mu-plugins" if you're using WordPress MU.
|
| 122 |
+
3. Is there a wp-content/advanced-cache.php ? If not, then you must symlink
|
| 123 |
+
wp-super-cache/wp-cache-phase1.php to it with the command while in the
|
| 124 |
+
wp-content folder:
|
| 125 |
+
ln -s plugins/wp-super-cache/wp-cache-phase1.php advanced-cache.php
|
| 126 |
+
If you can't do that, then copy the file. That will work too.
|
| 127 |
+
4. Make sure the following line is in wp-config.php
|
| 128 |
+
define( 'WP_CACHE', true );
|
| 129 |
+
5. Try the Options->WP Super Cache page again and enable cache.
|
| 130 |
+
6. Look in wp-content/cache/supercache/. Are there directories and files there?
|
| 131 |
+
7. Anything in your php error_log?
|
| 132 |
+
8. If your browser keeps asking you to save the file after the super cache is installed
|
| 133 |
+
you must disable Super Cache compression. Go to the Options->WP Super Cache page and disable
|
| 134 |
+
it there.
|
| 135 |
+
|
| 136 |
+
== Custom Caching ==
|
| 137 |
+
It is now possible to hook into the caching process using the add_cacheacton() function.
|
| 138 |
+
Three hooks are available:
|
| 139 |
+
|
| 140 |
+
1. 'wp_cache_get_cookies_values' - modify the key used by WP Cache.
|
| 141 |
+
2. 'add_cacheaction' - runs in phase2. Allows a plugin to add WordPress hooks.
|
| 142 |
+
3. 'cache_admin_page' - runs in the admin page. Use it to add modify that page.
|
| 143 |
+
|
| 144 |
+
There is one regular WordPress filter too. Use the "do_createsupercache" filter
|
| 145 |
+
to customize the checks made before caching. The filter accepts one parameter.
|
| 146 |
+
The output of WP-Cache's wp_cache_get_cookies_values() function.
|
| 147 |
+
|
| 148 |
+
See plugins/searchengine.php as an example I use for my [No Adverts for Friends](plugin at http://ocaoimh.ie/no-adverts-for-friends/)
|
| 149 |
+
|
| 150 |
+
== Updates ==
|
| 151 |
+
Updates to the plugin will be posted here, to http://ocaoimh.ie/ and the page
|
| 152 |
+
http://ocaoimh.ie/wp-super-cache/ will always link to the newest version.
|
| 153 |
+
|
| 154 |
+
== Thanks ==
|
| 155 |
+
I would sincerely like to thank [John Pozadzides](http://onemansblog.com/) for
|
| 156 |
+
giving me the idea for this, for writing the "How it works" section and for
|
| 157 |
+
testing the plugin through 2 front page appearances on digg.com
|
| 158 |
+
Thanks to James Farmer and Andrew Billits of [Edu Blogs](http://edublogs.org/) fame who helped me
|
| 159 |
+
make this more WordPress MU friendly.
|
wp-cache-phase1.php
CHANGED
|
@@ -30,7 +30,20 @@ $file_expired = false;
|
|
| 30 |
$cache_filename = '';
|
| 31 |
$meta_file = '';
|
| 32 |
|
| 33 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
$cache_filename = $file_prefix . $key . '.html';
|
| 35 |
$meta_file = $file_prefix . $key . '.meta';
|
| 36 |
$cache_file = $cache_path . $cache_filename;
|
|
@@ -45,7 +58,6 @@ if( ($mtime = @filemtime($meta_pathname)) ) {
|
|
| 45 |
foreach ($meta->headers as $header) {
|
| 46 |
header($header);
|
| 47 |
}
|
| 48 |
-
$log = "<!-- Cached page served by WP-Cache -->\n";
|
| 49 |
if ( !($content_size = @filesize($cache_file)) > 0 || $mtime < @filemtime($cache_file))
|
| 50 |
return;
|
| 51 |
if ($meta->dynamic) {
|
|
@@ -58,7 +70,6 @@ if( ($mtime = @filemtime($meta_pathname)) ) {
|
|
| 58 |
if(!@readfile ($cache_file))
|
| 59 |
return;
|
| 60 |
}
|
| 61 |
-
echo $log;
|
| 62 |
die;
|
| 63 |
}
|
| 64 |
$file_expired = true; // To signal this file was expired
|
| 30 |
$cache_filename = '';
|
| 31 |
$meta_file = '';
|
| 32 |
|
| 33 |
+
$wp_cache_gzip_encoding = '';
|
| 34 |
+
|
| 35 |
+
function gzip_accepted(){
|
| 36 |
+
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false) return false;
|
| 37 |
+
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') === false) return 'gzip';
|
| 38 |
+
return 'x-gzip';
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if ($cache_compression) {
|
| 42 |
+
$wp_cache_gzip_encoding = gzip_accepted();
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
$key = $blogcacheid . md5($_SERVER['HTTP_HOST'].preg_replace('/#.*$/', '', $_SERVER['REQUEST_URI']).$wp_cache_gzip_encoding.wp_cache_get_cookies_values());
|
| 46 |
+
|
| 47 |
$cache_filename = $file_prefix . $key . '.html';
|
| 48 |
$meta_file = $file_prefix . $key . '.meta';
|
| 49 |
$cache_file = $cache_path . $cache_filename;
|
| 58 |
foreach ($meta->headers as $header) {
|
| 59 |
header($header);
|
| 60 |
}
|
|
|
|
| 61 |
if ( !($content_size = @filesize($cache_file)) > 0 || $mtime < @filemtime($cache_file))
|
| 62 |
return;
|
| 63 |
if ($meta->dynamic) {
|
| 70 |
if(!@readfile ($cache_file))
|
| 71 |
return;
|
| 72 |
}
|
|
|
|
| 73 |
die;
|
| 74 |
}
|
| 75 |
$file_expired = true; // To signal this file was expired
|
wp-cache-phase2.php
CHANGED
|
@@ -9,6 +9,7 @@ $new_cache = false;
|
|
| 9 |
|
| 10 |
function wp_cache_phase2() {
|
| 11 |
global $cache_filename, $cache_acceptable_files, $wp_cache_meta_object;
|
|
|
|
| 12 |
|
| 13 |
wp_cache_mutex_init();
|
| 14 |
if(function_exists('add_action')) {
|
|
@@ -43,6 +44,7 @@ function wp_cache_phase2() {
|
|
| 43 |
|
| 44 |
function wp_cache_get_response_headers() {
|
| 45 |
if(function_exists('apache_response_headers')) {
|
|
|
|
| 46 |
$headers = apache_response_headers();
|
| 47 |
} else if(function_exists('headers_list')) {
|
| 48 |
$headers = array();
|
|
@@ -117,8 +119,9 @@ function wp_cache_writers_exit() {
|
|
| 117 |
}
|
| 118 |
|
| 119 |
function wp_cache_ob_callback($buffer) {
|
| 120 |
-
global $cache_path, $cache_filename, $meta_file, $wp_start_time;
|
| 121 |
global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id, $cache_compression;
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
/* Mode paranoic, check for closing tags
|
|
@@ -142,22 +145,27 @@ function wp_cache_ob_callback($buffer) {
|
|
| 142 |
if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) {
|
| 143 |
$dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])).preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI']) ); // To avoid XSS attacs
|
| 144 |
$dir = trailingslashit( $cache_path . 'supercache/' . $dir );
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
if( is_dir( $dir ) == false && is_dir( substr( $dir, 0, -1 ) . '.disabled' ) == false ) {
|
| 149 |
-
@mkpath( $dir );
|
| 150 |
}
|
| 151 |
|
| 152 |
$fr = @fopen($cache_path . $cache_filename, 'w');
|
| 153 |
if (!$fr)
|
| 154 |
$buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n";
|
| 155 |
-
$
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
}
|
| 162 |
|
| 163 |
if (preg_match('/<!--mclude|<!--mfunc/', $buffer)) { //Dynamic content
|
|
@@ -175,7 +183,21 @@ function wp_cache_ob_callback($buffer) {
|
|
| 175 |
if( $gz )
|
| 176 |
gzwrite($gz, $store . '<!-- super cache gz -->' );
|
| 177 |
} else {
|
| 178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
if( $fr2 )
|
| 180 |
fputs($fr2, $buffer . '<!-- super cache -->' );
|
| 181 |
if( $gz )
|
|
@@ -269,7 +291,6 @@ function wp_cache_shutdown_callback() {
|
|
| 269 |
$wp_cache_meta_object->post = wp_cache_post_id();
|
| 270 |
|
| 271 |
$response = wp_cache_get_response_headers();
|
| 272 |
-
$wp_cache_meta_object->headers = array();
|
| 273 |
foreach ($known_headers as $key) {
|
| 274 |
if(isset($response{$key})) {
|
| 275 |
array_push($wp_cache_meta_object->headers, "$key: " . $response{$key});
|
| 9 |
|
| 10 |
function wp_cache_phase2() {
|
| 11 |
global $cache_filename, $cache_acceptable_files, $wp_cache_meta_object;
|
| 12 |
+
global $wp_cache_gzip_encoding;
|
| 13 |
|
| 14 |
wp_cache_mutex_init();
|
| 15 |
if(function_exists('add_action')) {
|
| 44 |
|
| 45 |
function wp_cache_get_response_headers() {
|
| 46 |
if(function_exists('apache_response_headers')) {
|
| 47 |
+
flush();
|
| 48 |
$headers = apache_response_headers();
|
| 49 |
} else if(function_exists('headers_list')) {
|
| 50 |
$headers = array();
|
| 119 |
}
|
| 120 |
|
| 121 |
function wp_cache_ob_callback($buffer) {
|
| 122 |
+
global $cache_path, $cache_filename, $meta_file, $wp_start_time, $supercachedir;
|
| 123 |
global $new_cache, $wp_cache_meta_object, $file_expired, $blog_id, $cache_compression;
|
| 124 |
+
global $wp_cache_gzip_encoding, $super_cache_enabled;
|
| 125 |
|
| 126 |
|
| 127 |
/* Mode paranoic, check for closing tags
|
| 145 |
if( !((!$file_expired && $mtime) || ($mtime && $file_expired && (time() - $mtime) < 5)) ) {
|
| 146 |
$dir = strtolower(preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"])).preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI']) ); // To avoid XSS attacs
|
| 147 |
$dir = trailingslashit( $cache_path . 'supercache/' . $dir );
|
| 148 |
+
$supercachedir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
|
| 149 |
+
if( $super_cache_enabled == true && is_dir( substr( $supercachedir, 0, -1 ) . '.disabled' ) ) {
|
| 150 |
+
$super_cache_enabled = false;
|
|
|
|
|
|
|
| 151 |
}
|
| 152 |
|
| 153 |
$fr = @fopen($cache_path . $cache_filename, 'w');
|
| 154 |
if (!$fr)
|
| 155 |
$buffer = "Couldn't write to: " . $cache_path . $cache_filename . "\n";
|
| 156 |
+
if( $super_cache_enabled ) {
|
| 157 |
+
if( is_dir( $dir ) == false )
|
| 158 |
+
@mkpath( $dir );
|
| 159 |
+
|
| 160 |
+
$user_info = wp_cache_get_cookies_values();
|
| 161 |
+
$do_cache = apply_filters( 'do_createsupercache', $user_info );
|
| 162 |
+
if( $user_info == '' || $do_cache === true ) {
|
| 163 |
+
if( !is_feed() ) { // don't super cache feeds
|
| 164 |
+
$fr2 = @fopen("{$dir}index.html", 'w');
|
| 165 |
+
if( $cache_compression )
|
| 166 |
+
$gz = @gzopen("{$dir}index.html.gz", 'w3');
|
| 167 |
+
}
|
| 168 |
+
}
|
| 169 |
}
|
| 170 |
|
| 171 |
if (preg_match('/<!--mclude|<!--mfunc/', $buffer)) { //Dynamic content
|
| 183 |
if( $gz )
|
| 184 |
gzwrite($gz, $store . '<!-- super cache gz -->' );
|
| 185 |
} else {
|
| 186 |
+
$log = "<!-- Cached page served by WP-Cache -->\n";
|
| 187 |
+
|
| 188 |
+
if ($wp_cache_gzip_encoding) {
|
| 189 |
+
$log .= "<!-- Compression = " . $wp_cache_gzip_encoding ." -->";
|
| 190 |
+
$gzdata = gzencode($buffer . $log, 3, FORCE_GZIP);
|
| 191 |
+
$gzsize = strlen($gzdata);
|
| 192 |
+
|
| 193 |
+
array_push($wp_cache_meta_object->headers, 'Content-Encoding: ' . $wp_cache_gzip_encoding);
|
| 194 |
+
array_push($wp_cache_meta_object->headers, 'Vary: Accept-Encoding');
|
| 195 |
+
array_push($wp_cache_meta_object->headers, 'Content-Length: ' . strlen($gzdata));
|
| 196 |
+
// Return uncompressed data & store compressed for later use
|
| 197 |
+
fputs($fr, $gzdata);
|
| 198 |
+
}else{ // no compression
|
| 199 |
+
fputs($fr, $buffer.$log);
|
| 200 |
+
}
|
| 201 |
if( $fr2 )
|
| 202 |
fputs($fr2, $buffer . '<!-- super cache -->' );
|
| 203 |
if( $gz )
|
| 291 |
$wp_cache_meta_object->post = wp_cache_post_id();
|
| 292 |
|
| 293 |
$response = wp_cache_get_response_headers();
|
|
|
|
| 294 |
foreach ($known_headers as $key) {
|
| 295 |
if(isset($response{$key})) {
|
| 296 |
array_push($wp_cache_meta_object->headers, "$key: " . $response{$key});
|
wp-cache.php
CHANGED
|
@@ -114,7 +114,8 @@ function wp_cache_manager() {
|
|
| 114 |
$cache_compression_changed = true;
|
| 115 |
$cache_compression = intval( $_POST[ 'cache_compression' ] );
|
| 116 |
wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
|
| 117 |
-
|
|
|
|
| 118 |
delete_option( 'super_cache_meta' );
|
| 119 |
}
|
| 120 |
}
|
|
@@ -130,7 +131,7 @@ function wp_cache_manager() {
|
|
| 130 |
<p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
|
| 131 |
<?php
|
| 132 |
if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
|
| 133 |
-
?><p><strong>Super Cache compression is now disabled.
|
| 134 |
<blockquote style='background-color: #ff6'><code>RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$<br />
|
| 135 |
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$<br />
|
| 136 |
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$<br />
|
|
@@ -645,13 +646,15 @@ function wp_cache_clean_cache($file_prefix) {
|
|
| 645 |
|
| 646 |
// If phase2 was compiled, use its function to avoid race-conditions
|
| 647 |
if(function_exists('wp_cache_phase2_clean_cache')) {
|
| 648 |
-
if(
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
}
|
| 653 |
-
prune_super_cache( $cache_path, true );
|
| 654 |
-
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
|
| 655 |
return wp_cache_phase2_clean_cache($file_prefix);
|
| 656 |
}
|
| 657 |
|
|
@@ -672,13 +675,15 @@ function wp_cache_clean_expired($file_prefix) {
|
|
| 672 |
|
| 673 |
// If phase2 was compiled, use its function to avoid race-conditions
|
| 674 |
if(function_exists('wp_cache_phase2_clean_expired')) {
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
|
|
|
|
|
|
|
|
|
| 680 |
}
|
| 681 |
-
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
|
| 682 |
return wp_cache_phase2_clean_expired($file_prefix);
|
| 683 |
}
|
| 684 |
|
| 114 |
$cache_compression_changed = true;
|
| 115 |
$cache_compression = intval( $_POST[ 'cache_compression' ] );
|
| 116 |
wp_cache_replace_line('^ *\$cache_compression', "\$cache_compression = " . $cache_compression . ";", $wp_cache_config_file);
|
| 117 |
+
if( function_exists( 'prune_super_cache' ) )
|
| 118 |
+
prune_super_cache ($cache_path, true);
|
| 119 |
delete_option( 'super_cache_meta' );
|
| 120 |
}
|
| 121 |
}
|
| 131 |
<p>Compression is disabled by default because some hosts have problems with compressed files. Switching this on and off clears the cache.</p>
|
| 132 |
<?php
|
| 133 |
if( isset( $cache_compression_changed ) && isset( $_POST[ 'cache_compression' ] ) && !$cache_compression ) {
|
| 134 |
+
?><p><strong>Super Cache compression is now disabled. For maximum performance you should remove or comment out the following rules in your .htaccess file:</strong></p>
|
| 135 |
<blockquote style='background-color: #ff6'><code>RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$<br />
|
| 136 |
RewriteCond %{HTTP_COOKIE} !^.*wordpressuser.*$<br />
|
| 137 |
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$<br />
|
| 646 |
|
| 647 |
// If phase2 was compiled, use its function to avoid race-conditions
|
| 648 |
if(function_exists('wp_cache_phase2_clean_cache')) {
|
| 649 |
+
if (function_exists ('prune_super_cache')) {
|
| 650 |
+
if( is_dir( $supercachedir ) ) {
|
| 651 |
+
prune_super_cache( $supercachedir, true );
|
| 652 |
+
} elseif( is_dir( $supercachedir . '.disabled' ) ) {
|
| 653 |
+
prune_super_cache( $supercachedir . '.disabled', true );
|
| 654 |
+
}
|
| 655 |
+
prune_super_cache( $cache_path, true );
|
| 656 |
+
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
|
| 657 |
}
|
|
|
|
|
|
|
| 658 |
return wp_cache_phase2_clean_cache($file_prefix);
|
| 659 |
}
|
| 660 |
|
| 675 |
|
| 676 |
// If phase2 was compiled, use its function to avoid race-conditions
|
| 677 |
if(function_exists('wp_cache_phase2_clean_expired')) {
|
| 678 |
+
if (function_exists ('prune_super_cache')) {
|
| 679 |
+
$dir = $cache_path . 'supercache/' . preg_replace('/:.*$/', '', $_SERVER["HTTP_HOST"]);
|
| 680 |
+
if( is_dir( $dir ) ) {
|
| 681 |
+
prune_super_cache( $dir );
|
| 682 |
+
} elseif( is_dir( $dir . '.disabled' ) ) {
|
| 683 |
+
prune_super_cache( $dir . '.disabled' );
|
| 684 |
+
}
|
| 685 |
+
$_POST[ 'super_cache_stats' ] = 1; // regenerate super cache stats;
|
| 686 |
}
|
|
|
|
| 687 |
return wp_cache_phase2_clean_expired($file_prefix);
|
| 688 |
}
|
| 689 |
|
