Commit 6c8d3e02 authored by lechuck's avatar lechuck Committed by lechuck

Upgrade WP super cache to 1.1

parent 4ec8e341
......@@ -14,6 +14,8 @@ if ( get_option( 'ossdl_off_exclude' ) == false )
add_option('ossdl_off_exclude', '.php');
$ossdl_off_exclude = trim(get_option('ossdl_off_exclude'));
$arr_of_excludes = array_map('trim', explode(',', $ossdl_off_exclude));
if ( !is_array( $arr_of_excludes ) )
$arr_of_excludes = array();
if ( get_option( 'ossdl_cname' ) == false )
add_option('ossdl_cname', '');
......@@ -38,6 +40,16 @@ function scossdl_off_exclude_match($match, $excludes) {
return false;
}
/**
* Compute string modulo, based on SHA1 hash
*/
function scossdl_string_mod($s, $mod) {
/* The full SHA1 is too large for PHP integer types. This should be
* enough for our purpose */
$n = hexdec(substr(sha1($s), 0, 5));
return $n % $mod;
}
/**
* Rewriter of URLs, used as replace-callback.
*
......@@ -45,30 +57,23 @@ function scossdl_off_exclude_match($match, $excludes) {
*/
function scossdl_off_rewriter($match) {
global $ossdl_off_blog_url, $ossdl_off_cdn_url, $arr_of_excludes, $arr_of_cnames, $ossdl_https;
static $offset = -1;
static $rewritten_urls = array();
if ( $ossdl_https && substr( $match[0], 0, 5 ) == 'https' )
if ( $ossdl_off_cdn_url == '' )
return $match[0];
if ( isset( $rewritten_urls[ $match[ 0 ] ] ) )
return $rewritten_urls[ $match[ 0 ] ];
if ( $ossdl_https && substr( $match[0], 0, 5 ) == 'https' )
return $match[0];
if ( false == in_array( $ossdl_off_cdn_url, $arr_of_cnames ) )
$arr_of_cnames[] = $ossdl_off_cdn_url;
if (scossdl_off_exclude_match($match[0], $arr_of_excludes)) {
if ( scossdl_off_exclude_match( $match[0], $arr_of_excludes ) ) {
return $match[0];
} else {
$include_dirs = scossdl_off_additional_directories();
if ( preg_match( '/' . $include_dirs . '/', $match[0] ) ) {
$offset++;
$offset %= count($arr_of_cnames);
$url = str_replace($ossdl_off_blog_url, $arr_of_cnames[$offset], $match[0]);
if ( count( $rewritten_urls ) < 30 ) // don't use too much memory please
$rewritten_urls[ $match[ 0 ] ] = $url;
return $url;
$offset = scossdl_string_mod($match[1], count($arr_of_cnames));
return str_replace($ossdl_off_blog_url, $arr_of_cnames[$offset], $match[0]);
} else {
return $match[0];
}
......
......@@ -30,9 +30,24 @@ function domain_mapping_gc_cache( $function, $directory ) {
return $directory;
}
function domain_mapping_supercachedir( $dir ) {
global $cache_path;
if ( !function_exists( 'domain_mapping_warning' ) )
return $dir;
$siteurl = domain_mapping_siteurl( false );
if ( !$siteurl )
return $dir;
$protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
$siteurl = str_replace( $protocol, '', $siteurl );
return $cache_path . 'supercache/' . $siteurl;
}
function domain_mapping_actions() {
global $cache_domain_mapping;
if( $cache_domain_mapping == '1' ) {
add_filter( 'wp_super_cache_supercachedir', 'domain_mapping_supercachedir' );
add_action( 'gc_cache', 'domain_mapping_gc_cache', 10, 2 );
}
}
......
<?php
if ( defined( 'WP_ALLOW_MULTISITE' ) )
add_cacheaction( 'add_cacheaction', 'wp_super_cache_multisite_init' );
function wp_super_cache_multisite_init() {
add_filter( 'wpmu_blogs_columns', 'wp_super_cache_blogs_col' );
add_action( 'manage_sites_custom_column', 'wp_super_cache_blogs_field', 10, 2 );
add_action( 'init', 'wp_super_cache_override_on_flag' );
}
function wp_super_cache_blogs_col( $col ) {
$col[ 'wp_super_cache' ] = __( 'Cached', 'wp-super-cache' );
return $col;
}
function wp_super_cache_blogs_field( $name, $blog_id ) {
if ( $name != 'wp_super_cache' )
return false;
if ( isset( $_GET[ 'id' ] ) && $blog_id == $_GET[ 'id' ] ) {
$valid_nonce = isset( $_GET[ '_wpnonce' ] ) ? wp_verify_nonce( $_GET[ '_wpnonce' ], 'wp-cache' . $_GET[ 'id' ] ) : false;
if ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'disable_cache' ) {
add_blog_option( $_GET[ 'id' ], 'wp_super_cache_disabled', 1 );
} elseif ( $valid_nonce && isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'enable_cache' ) {
delete_blog_option( $_GET[ 'id' ], 'wp_super_cache_disabled' );
}
}
if ( get_blog_option( $blog_id, 'wp_super_cache_disabled' ) == 1 ) {
echo "<a href='" . wp_nonce_url( add_query_arg( array( 'action' => 'enable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . "'>" . __( 'Enable', 'wp-super-cache' ) . "</a>";
} else {
echo "<a href='" . wp_nonce_url( add_query_arg( array( 'action' => 'disable_cache', 'id' => $blog_id ) ), 'wp-cache' . $blog_id ) . "'>" . __( 'Disable', 'wp-super-cache' ) . "</a>";
}
}
function wp_super_cache_multisite_notice() {
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' )
echo '<div class="error"><p><strong>' . __( 'Caching has been disabled on this blog on the Network Admin Sites page.', 'wp-super-cache' ) . '</strong></p></div>';
}
function wp_super_cache_override_on_flag() {
global $cache_enabled, $super_cache_enabled;
if ( $cache_enabled != true )
return false;
if ( get_option( 'wp_super_cache_disabled' ) ) {
$cache_enabled = false;
$super_cache_enabled = false;
define( 'DONOTCACHEPAGE', 1 );
define( "SUBMITDISABLED", 'disabled style="color: #aaa" ' );
if ( is_admin() )
add_action( 'admin_notices', 'wp_super_cache_multisite_notice' );
}
}
?>
......@@ -61,21 +61,28 @@ function wp_supercache_searchengine_admin() {
$cache_no_adverts_for_friends = $_POST['cache_no_adverts_for_friends'] == __( 'Disable', 'wp-super-cache' ) ? 'no' : 'yes';
wp_cache_replace_line('^ *\$cache_no_adverts_for_friends', "\$cache_no_adverts_for_friends = '$cache_no_adverts_for_friends';", $wp_cache_config_file);
}
echo '<li><form name="wp_supercache_searchengine_admin" action="'. $_SERVER["REQUEST_URI"] . '" method="post">';
$id = 'no_adverts_for_friends-section';
?>
<fieldset id="<?php echo $id; ?>" class="options">
<h4><?php _e( 'No Adverts for Friends', 'wp-super-cache' ); ?></h4>
<form name="wp_manager" action="<?php echo $_SERVER[ "REQUEST_URI" ]; ?>" method="post">
<label><input type="radio" name="cache_no_adverts_for_friends" value="1" <?php if( $cache_no_adverts_for_friends == 'yes' ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_no_adverts_for_friends" value="0" <?php if( $cache_no_adverts_for_friends == 'no' ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . __( 'Provides support for <a href="http://ocaoimh.ie/no-adverts-for-friends/">No Adverts for Friends</a>.', 'wp-super-cache' ) . '</p>';
if ($changed) {
if ( 'yes' == $cache_no_adverts_for_friends )
$status = __( "enabled" );
else
$status = __( "disabled" );
echo "<p><strong>" . sprintf( __( "No Adverts for Friends support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
}
echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field('wp-cache');
if( $cache_no_adverts_for_friends == 'no' ) {
$status = __( 'disabled', 'wp-super-cache' );
} else {
$status = __( 'enabled', 'wp-super-cache' );
}
echo '<strong>' . sprintf( __( '<a href="http://ocaoimh.ie/no-adverts-for-friends/">No Adverts for Friends</a> plugin is %s.', 'wp-super-cache' ), $status );
echo '</strong> ' . __( '(requires <a href="http://ocaoimh.ie/no-adverts-for-friends/">friendsadverts.php</a> too) ', 'wp-super-cache' );
if( $cache_no_adverts_for_friends == 'no' ) {
echo '<input type="submit" name="cache_no_adverts_for_friends" value="' . __( 'Enable', 'wp-super-cache' ) . '" />';
} else {
echo '<input type="submit" name="cache_no_adverts_for_friends" value="' . __( 'Disable', 'wp-super-cache' ) . '" />';
}
echo "</form></li>\n";
?>
</form>
</fieldset>
<?php
}
add_cacheaction( 'cache_admin_page', 'wp_supercache_searchengine_admin' );
......
<?php
function wp_super_cache_wptouch_admin() {
global $cache_wptouch, $wp_cache_config_file, $valid_nonce;
$cache_wptouch = $cache_wptouch == '' ? '0' : $cache_wptouch;
if(isset($_POST['cache_wptouch']) && $valid_nonce) {
if ( $cache_wptouch == (int)$_POST['cache_wptouch'] ) {
$changed = false;
} else {
$changed = true;
}
$cache_wptouch = (int)$_POST['cache_wptouch'];
wp_cache_replace_line('^ *\$cache_wptouch', "\$cache_wptouch = '$cache_wptouch';", $wp_cache_config_file);
}
$id = 'wptouch-section';
?>
<fieldset id="<?php echo $id; ?>" class="options">
<h4><?php _e( 'WPTouch', 'wp-super-cache' ); ?></h4>
<form name="wp_manager" action="<?php echo $_SERVER[ "REQUEST_URI" ]; ?>" method="post">
<label><input type="radio" name="cache_wptouch" value="1" <?php if( $cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Enabled', 'wp-super-cache' ); ?></label>
<label><input type="radio" name="cache_wptouch" value="0" <?php if( !$cache_wptouch ) { echo 'checked="checked" '; } ?>/> <?php _e( 'Disabled', 'wp-super-cache' ); ?></label>
<p><?php _e( '', 'wp-super-cache' ); ?></p><?php
echo '<p>' . __( 'Provides support for <a href="http://wordpress.org/extend/plugins/wptouch/">WPTouch</a> mobile theme and plugin.', 'wp-super-cache' ) . '</p>';
if ($changed) {
if ( $cache_wptouch )
$status = __( "enabled" );
else
$status = __( "disabled" );
echo "<p><strong>" . sprintf( __( "WPTouch support is now %s", 'wp-super-cache' ), $status ) . "</strong></p>";
}
echo '<div class="submit"><input ' . SUBMITDISABLED . 'type="submit" value="' . __( 'Update', 'wp-super-cache' ) . '" /></div>';
wp_nonce_field('wp-cache');
?>
</form>
</fieldset>
<?php
}
add_cacheaction( 'cache_admin_page', 'wp_super_cache_wptouch_admin' );
function wp_super_cache_wptouch_notice() {
global $cache_enabled, $cache_wptouch;
if( $cache_enabled )
echo '<div class="error"><p><strong>' . __('WPTouch plugin detected! Please go to the Supercache plugins page and enable the WPTouch helper plugin.', 'wp-super-cache' ) . '</strong></p></div>';
}
function wp_super_cache_wptouch_exists() {
global $cache_wptouch;
if ( $cache_wptouch == 1 )
return false;
if ( is_admin() && function_exists( 'wptouch_get_plugin_dir_name' ) )
add_action( 'admin_notices', 'wp_super_cache_wptouch_notice' );
}
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'wpsupercache' ) {
add_cacheaction( 'add_cacheaction', 'wp_super_cache_wptouch_exists' );
}
// disable mobile checking if
function wp_super_cache_maybe_disable_wptouch( $t ) {
global $cache_wptouch, $wptouch_exclude_ua;
if ( $cache_wptouch != 1 )
return false;
if ( isset( $_COOKIE[ 'wptouch_switch_toggle' ] ) && $_COOKIE['wptouch_switch_toggle'] == 'normal' )
return true;
$ua = explode( ",", $wptouch_exclude_ua );
foreach( $ua as $agent ) {
if ( preg_match( "#$agent#i", $_SERVER[ 'HTTP_HOST' ] ) )
return true; // disable mobile ua check if matches the exclude list in wptouch
}
return false;
}
add_cacheaction( 'disable_mobile_check', 'wp_super_cache_maybe_disable_wptouch' );
function wp_super_cache_wptouch_browsers( $browsers ) {
global $cache_wptouch, $wptouch_exclude_ua, $wp_cache_config_file;
if ( false == function_exists( 'bnc_wptouch_get_exclude_user_agents' ) || false == function_exists( 'bnc_wptouch_get_user_agents' ) )
return $browsers;
$browsers = implode( ',', bnc_wptouch_get_exclude_user_agents() ); // hack, support exclude agents too
if ( $browsers != $wptouch_exclude_ua ) {
wp_cache_replace_line('^ *\$wptouch_exclude_ua', "\$wptouch_exclude_ua = '$browsers';", $wp_cache_config_file);
$wptouch_exclude_ua = $browsers;
}
return bnc_wptouch_get_user_agents();
}
function wp_super_cache_wptouch_prefixes( $prefixes ) {
return array(); // wptouch doesn't support UA prefixes
}
function wp_super_cache_wptouch_cookie_check( $cache_key ) {
if ( false == isset( $_COOKIE[ 'wptouch_switch_toggle' ] ) )
return $cache_key;
if ( $_COOKIE[ 'wptouch_switch_toggle' ] == 'normal' || $_COOKIE[ 'wptouch_switch_toggle' ] == 'mobile' )
return $_COOKIE[ 'wptouch_switch_toggle' ];
return $cache_key;
}
if ( $cache_wptouch == 1 ) {
add_cacheaction( 'wp_super_cache_mobile_browsers', 'wp_super_cache_wptouch_browsers' );
add_cacheaction( 'wp_super_cache_mobile_prefixes', 'wp_super_cache_wptouch_prefixes' );
add_cacheaction( 'wp_cache_check_mobile', 'wp_super_cache_wptouch_cookie_check' );
}
?>
=== WP Super Cache ===
Contributors: donncha, automattic
Tags: performance,caching,wp-cache,wp-super-cache,cache
Tested up to: 3.2
Stable tag: 0.9.9.9
Requires at least: 2.9.2
Tested up to: 3.4
Stable tag: 1.1
Requires at least: 3.0
A very fast caching engine for WordPress that produces static html files.
......@@ -52,13 +52,56 @@ The [changelog](http://svn.wp-plugins.org/wp-super-cache/trunk/Changelog.txt) is
Interested in translating WP Super Cache to your language? Grab the [development version](http://downloads.wordpress.org/plugin/wp-super-cache.zip) where you will find an up to date wp-super-cache.pot. Send any translation files to donncha @ ocaoimh.ie and thank you!
The cache directory, usually wp-content/cache/ is only for temporary files. Do not ever put important files or symlinks to important files or directories in that directory. They will be deleted if the plugin has write access to them.
== Upgrade Notice ==
= 0.9.9.9 =
Serve repeated static files from the same CDN hostname, translations, lots of bug fixes
= 1.1 =
Lots of bugfixes
== Changelog ==
= 1.1 =
* Use $_SERVER[ 'SERVER_NAME' ] to create cache directories.
* Only create blogs cached directories if valid requests and blogs exist.
* Only clear current blog's cache files if navigation menu is modified
* Added clean_post_cache action to clear cache on post actions
* Removed garbage collection details on Contents tab
* Added wp_cache_check_mobile cacheaction filter to shortcircuit mobile device check.
* Don't delete cache files for draft posts
* Added action on wp_trash_post to clear the cache when trashed posts are deleted
* Show a warning when 304 browser caching is disabled (because mod_rewrite caching is on)
* New check for safe mode if using less that PHP 5.3.0
* Added wp_supercache_remove_cookies filter to disable anonymous browsing mode.
* Fixed garbage collection schedule dropdown
* Fixed preload problem clearing site's cache on "page on front" sites.
* Fix for PHP variable not defined warnings
* Fixed problem refreshing cache when comments made as siteurl() sometimes didn't work
* Preloading of taxonomies is now optional
* Domain mapping fixes.
* Better support for https sites. Remove https:// to get cache paths.
* Added AddDefaultCharset .htaccess rule back in and added an option to remove it if required.
* Added multisite plugin that adds a "Cached" column to Network->Sites to disable caching on a per site basis.
* Added WPTouch plugin to modify browser and prefix list in mobile detection code. Added support for that plugin's exclude list.
* Fixed cache tester
* Filter the tags that are used to detect end-of-page using the wp_cache_eof_tags filter.
* Removed debug level from logging as it wasn't helpful.
* Removed mention of wp-minify.
= 1.0 =
* Removed AddDefaultCharset .htaccess rule
* Fixed problem with blogs in a folder and don't have a trailing slash
* New scheduling of garbage collection
* Added a "Delete cache" link to admin bar to delete cache of current page.
* Updated documentation
* Sorry Digg, Stephen Fry power now!
* Updated translations
* Preload taxonomies and all post types except revisionsand nav menu items
* Fixed previews by logged in users.
* Added option to make logged in users anonymous
* Use WP 3.0 variables to detect multisite installs
* Hash filenames so files are served from the same CDNs
= 0.9.9.9 =
* Fixed typo, is_front_page.
* Serve repeated static files from the same CDN hostname.
......@@ -287,7 +330,7 @@ Enable debugging in the plugin settings page and load the log file in a new brow
In legacy caching mode, if you have compression enabled, the text "Compression = gzip" will be added. If compression is disabled and the page is served as a static html file, the text "super cache" will be added. The only other way to check if your cached file was served by PHP script or from the static cache is by looking at the HTTP headers. PHP cached pages will have the header "WP-Super-Cache: Served supercache file from PHP". Legacy cached files will have the header, "WP-Super-Cache: Served legacy cache file". I used the <a href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live HTTP Headers</a> extension for Firefox to examine the headers. You should also check your cache directory in wp-content/cache/supercache/hostname/ for static cache files.
If the plugin rules are missing from your .htaccess file, the plugin will attempt to serve the super cached page if it's found. The header "WP-Super-Cache: Served supercache file from PHP" if this happens.
= WP-Cache vs Supercache files =
= Legacy (WP-Cache) vs Supercache files =
WP-Cache files are stored in wp-content/cache/ (or on MU sites in a blogs sub directory) and are named wp-cache-XXXXXXXXXXXXXXXXX.html. Associated meta files are stored in a meta sub directory. Those files contain information about the cached file. These files are generated by the "legacy caching" code in the plugin.
Supercache files are stored in wp-content/cache/supercache/HOSTNAME/ where HOSTNAME is your domain name. The files are stored in directories matching your site's permalink structure.
......@@ -359,6 +402,10 @@ Cached files are served before almost all of WordPress is loaded. While that's g
This plugin caches entire pages but some plugins think they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript/AJAX methods or the dynamic-cached-content/mfunc/mclude code described in the previous answer to update or display dynamic information.
= What does the Cache Rebuild feature do? =
When a visitor leaves a comment the cached file for that page is deleted and the next visitor recreates the cached page. A page takes time to load so what happens if it receives 100 visitors during this time? There won't be a cached page so WordPress will serve a fresh page for each user and the plugin will try to create a cached page for each of those 100 visitors causing a huge load on your server. This feature stops this happening. The cached page is not cleared when a comment is left. It is marked for rebuilding instead. The next visitor will regenerate the cached page while the old page is served to the other 99 visitors. The page is eventually loaded by the first visitor and the cached page updated. See [this post](http://ocaoimh.ie/2009/01/23/wp-super-cache-089/) for more.
= Why doesn't the plugin cache requests by search engine bots by default? =
Those bots usually only visit each page once and if the page is not popular there's no point creating a cache file that will sit idle on your server. However if you're not using legacy caching you can allow these visits to be cached by removing the list of bots from "Rejected User Agents" on the Advanced settings page.
......@@ -386,7 +433,7 @@ That tracking adds a query string to each url linked from various sources like T
= The plugin complains that wp-content is writable! htdocs is writable! =
It's not good when the web server can write to these directories but sometimes shared hosting accounts are set up in this way to make administration easier. Use `chmod 755 directory` to fix the permissions or find the permissions section of your ftp client. This [Google search](http://www.google.ie/search?sourceid=chrome&ie=UTF-8&q=ftp+fix+directory+permissions+755) will lead you to more information on this topic. Unfortunately some hosts require that those directories be writable. If that's the case just ignore this warning.
It's not good when the web server can write to these directories but sometimes shared hosting accounts are set up in this way to make administration easier. Use `chmod 755 directory` to fix the permissions or find the permissions section of your ftp client. This [Google search](http://www.google.ie/search?sourceid=chrome&ie=UTF-8&q=ftp+fix+directory+permissions+755) will lead you to more information on this topic and there's also [this codex page](http://codex.wordpress.org/Changing_File_Permissions) too. Unfortunately some hosts require that those directories be writable. If that's the case just ignore this warning.
= How do I delete the WP_CACHE define from wp-config.php? =
......@@ -405,6 +452,18 @@ This [page](http://codex.wordpress.org/Changing_File_Permissions) on the WordPre
You may have the "clear all cached files when new posts are made" option set. Clearing those files can take time plus your visitors will now be visiting uncached pages. Are you using Google Analytics campaign tracking with utm_source in the url? Those pages aren't cached. See the question, "How should I best use the utm_source tracking tools in Google Analytics with this plugin" above for how to use them properly.
Cached pages have to be refreshed when posts are made. Perhaps your server just isn't up to the job of serving the amount of traffic you get. Enable the "cache rebuild" feature as that may help.
= How many pages can I cache? =
The only real limit are limits defined by your server. For example, EXT2 and EXT3 allow a maximum of 31,999 sub directories so if you have a flat permalink structure (like /%POSTNAME%/) and more than 32,000 posts you may run into problems. Likewise, if you run a multisite network and have more than 31,999 sites (blogs) you won't be able to cache all of them. Realistically if you had that many active sites you wouldn't be running on one server.
= How do I serve cached mobile pages to clients on small screens like phones and tablets? =
You'll have to use a separate mobile plugin to render a page formatted for those visitors. The following plugins have been tested but YMMV depending on mobile client.
* [WPTouch] (http://wordpress.org/extend/plugins/wptouch/)
* [WordPress Mobile Edition] (http://wordpress.org/extend/plugins/wordpress-mobile-edition/)
* [WordPress Mobile Pack] (http://wordpress.org/extend/plugins/wordpress-mobile-pack/) (can't have "Don't cache pages for known users." enabled)
= Troubleshooting =
If things don't work when you installed the plugin here are a few things to check:
......@@ -426,10 +485,9 @@ If things don't work when you installed the plugin here are a few things to chec
13. File locking errors such as "failed to acquire key 0x152b: Permission denied in..." or "Page not cached by WP Super Cache. Could not get mutex lock." are a sign that you may have to use file locking. Edit wp-content/wp-cache-config.php and uncomment "$use_flock = true" or set $sem_id to a different value. You can also disable file locking from the Admin screen as a last resort.
14. Make sure cache/wp_cache_mutex.lock is writable by the web server if using coarse file locking.
15. The cache folder cannot be put on an NFS or Samba or NAS share. It has to be on a local disk. File locking and deleting expired files will not work properly unless the cache folder is on the local machine.
16. Garbage collection of old cache files won't work if WordPress can't find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it's 404 or you don't see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more.
16. Garbage collection of old cache files won't work if WordPress can't find wp-cron.php. If your hostname resolves to 127.0.0.1 it could be preventing the garbage collection from working. Check your access_logs for wp-cron.php entries. Do they return a 404 (file not found) or 200 code? If it's 404 or you don't see wp-cron.php anywhere WordPress may be looking for that script in the wrong place. You should speak to your server administator to correct this or edit /etc/hosts on Unix servers and remove the following line. Your hostname must resolve to the external IP address other servers on the network/Internet use. See http://yoast.com/wp-cron-issues/ for more. A line like "127.0.0.1 localhost localhost.localdomain" is ok.
`127.0.0.1 myhostname.com`
A line like "127.0.0.1 localhost localhost.localdomain" is ok.
17. If old pages are being served to your visitors via the supercache, you may be missing Apache modules (or their equivalents if you don't use Apache). 3 modules are required: mod_mime, mod_headers and mod_expires. The last two are especially important for making sure browsers load new versions of existing pages on your site.
18. The error message, "WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed!" appears at the end of every page. Open the file wp-content/advanced-cache.php in your favourite editor. Is the path to wp-cache-phase1.php correct? This file will normally be in wp-content/plugins/wp-super-cache/. If it is not correct the caching engine will not load.
19. Caching doesn't work. The timestamp on my blog keeps changing when I reload. Check that the path in your .htaccess rules matches where the supercache directory is. You may have to hardcode it. Or use the plugin in PHP or legacy caching mode.
......@@ -439,12 +497,18 @@ A line like "127.0.0.1 localhost localhost.localdomain" is ok.
21. If you see garbage in your browser after enabling compression in the plugin, compression may already be enabled in your web server. In Apache you must disable mod_deflate, or in PHP zlib compression may be enabled. You can disable that in three ways. If you have root access, edit your php.ini and find the zlib.output_compression setting and make sure it's "Off" or add this line to your .htaccess:
`php_flag zlib.output_compression off`
If that doesn't work, add this line to your wp-config.php:
`ini_set('zlib.output_compression', 0);`
22. The "white screen of death" or a blank page when you visit your site is almost always caused by a PHP error but [it may also be caused by APC](http://www.johnberns.com/2010/03/19/wp-super-cache-blank-page-problem-fixed/). Disable that PHP extension if you have trouble and replace with eAccelerator or Xcache.
23. After uninstalling, your permalinks may break if you remove the WordPress mod_rewrite rules too. Regenerate those rules by visiting the Settings->Permalink page and saving that form again.
24. If your blog refuses to load make sure your wp-config.php is correct. Are you missing an opening or closing PHP tag?
25. Your front page is ok but posts and pages give a 404? Go to Settings->permalinks and click "Save" once you've selected a custom permalink structure. You may need to manually update your .htaccess file.
26. If certain characters do not appear correctly on your website your server may not be configured correctly. You need to tell visitors what character set is used. Go to Settings->Reading and copy the 'Encoding for pages and feeds' value. Edit the .htaccess file with all your Supercache and WordPress rewrite rules and add this at the top, replacing CHARSET with the copied value. (for example, 'UTF-8')
`AddDefaultCharset CHARSET`
27. Use [Cron View](http://wordpress.org/extend/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs.
== CDN ==
......@@ -491,5 +555,9 @@ Translators who did a great job converting the text of the plugin to their nativ
* [Maître Mô](http://maitremo.fr/) (French)
* [Mathias Roth](http://trade-service.eu/) (German)
* Bar¿¿ Ünver (Turkish)
* [Elvis Fweb](http://fweb.org.ru/blog/super-cache-rus) (Russian)
* [Elvis Fweb](http://wp.turkenichev.ru/) (Russian)
* Fredrik Forséll (Swedish)
* [Alyona Lompar](http://wwww.webhostinggeeks.com/) (Ukranian)
* [Nata Strazda](http://www.webhostingrating.com/) (Lithuanian)
* [Alexander Alexandrov](http://www.designcontest.com/) (Belarusian)
* [Michail Bogdanov](http://www.webhostinghub.com/) (Romanian)
......@@ -10,4 +10,26 @@ if (!class_exists('CacheMeta')) {
}
}
// We want to be able to identify each blog in a WordPress MU install
$blogcacheid = '';
if ( defined( 'VHOST' ) || ( defined( 'WP_ALLOW_MULTISITE' ) && constant( 'WP_ALLOW_MULTISITE' ) == true ) ) {
$blogcacheid = 'blog'; // main blog
if( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == true ) {
$blogcacheid = $_SERVER['SERVER_NAME'];
} else {
$request_uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI'] ) );
if( strpos( $request_uri, '/', 1 ) ) {
if( $base == '/' ) {
$blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
} else {
$blogcacheid = str_replace( $base, '', $request_uri );
$blogcacheid = substr( $blogcacheid, 0, strpos( $blogcacheid, '/', 1 ) );
}
if ( '/' == substr($blogcacheid, -1))
$blogcacheid = substr($blogcacheid, 0, -1);
}
$blogcacheid = str_replace( '/', '', $blogcacheid );
}
}
?>
......@@ -17,28 +17,6 @@ $cache_path = WP_CONTENT_DIR . '/cache/';
$file_prefix = 'wp-cache-';
$ossdlcdn = 0;
// We want to be able to identify each blog in a WordPress MU install
$blogcacheid = '';
if( defined( 'VHOST' ) ) {
$blogcacheid = 'blog'; // main blog
if( constant( 'VHOST' ) == 'yes' ) {
$blogcacheid = $_SERVER['HTTP_HOST'];
} else {
$request_uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI'] ) );
if( strpos( $request_uri, '/', 1 ) ) {
if( $base == '/' ) {
$blogcacheid = substr( $request_uri, 1, strpos( $request_uri, '/', 1 ) - 1 );
} else {
$blogcacheid = str_replace( $base, '', $request_uri );
$blogcacheid = substr( $blogcacheid, 0, strpos( $blogcacheid, '/', 1 ) );
}
if ( '/' == substr($blogcacheid, -1))
$blogcacheid = substr($blogcacheid, 0, -1);
}
$blogcacheid = str_replace( '/', '', $blogcacheid );
}
}
// Array of files that have 'wp-' but should still be cached
$cache_acceptable_files = array( 'wp-comments-popup.php', 'wp-links-opml.php', 'wp-locations.php' );
......
......@@ -10,6 +10,9 @@ if( !include( WP_CONTENT_DIR . '/wp-cache-config.php' ) )
if( !defined( 'WPCACHEHOME' ) )
define('WPCACHEHOME', dirname(__FILE__).'/');
if ( false == isset( $_SERVER[ 'SERVER_NAME' ] ) && true == isset( $_SERVER[ 'HTTP_HOST' ] ) )
$_SERVER[ 'SERVER_NAME' ] = $_SERVER[ 'HTTP_HOST' ];
include( WPCACHEHOME . 'wp-cache-base.php');
if( $blogcacheid != '' ) {
......@@ -26,6 +29,13 @@ if( !isset( $wp_cache_plugins_dir ) )
require_once( WPCACHEHOME . 'wp-cache-phase2.php');
if ( isset( $_GET[ 'donotcachepage' ] ) && isset( $cache_page_secret ) && $_GET[ 'donotcachepage' ] == $cache_page_secret ) {
$cache_enabled = false;
define( 'DONOTCACHEPAGE', 1 );
}
if ( isset( $wp_cache_make_known_anon ) && $wp_cache_make_known_anon )
wp_supercache_cache_for_admins();
$plugins = glob( $wp_cache_plugins_dir . '/*.php' );
if( is_array( $plugins ) ) {
foreach ( $plugins as $plugin ) {
......@@ -34,6 +44,8 @@ if( is_array( $plugins ) ) {
}
}
do_cacheaction( 'cache_init' );
if (!$cache_enabled || $_SERVER["REQUEST_METHOD"] == 'POST')
return true;
......@@ -49,7 +61,7 @@ function gzip_accepted(){
if ( 1 == ini_get( 'zlib.output_compression' ) || "on" == strtolower( ini_get( 'zlib.output_compression' ) ) ) // don't compress WP-Cache data files when PHP is already doing it
return false;
if (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false) return false;
if ( isset( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ] ) && strpos( $_SERVER[ 'HTTP_ACCEPT_ENCODING' ], 'gzip' ) === false ) return false;
return 'gzip';
}