wp-cache on IIS – Finally

After I don’t know how many attempts to get wp-cache, wp-supercache and diggDefender to work in an IIS/Windows environment. Somehow, I never stumbled upon the article at Fanrastic or I never implemented it just right. Because I got it working in a matter of minutes. I’ve copied the steps below (for my own personal archive), so please don’t ask questions or give thanks – direct those to Fanrastic.

  1. Download the WP-Cache zip file (current version as of writing is 2.1.1) and unzip into wp-content/plugins folder.
  2. If you’re planning to run WP-Cache on IIS, you’ll first need to update wp-cache-phase1.php. Problem is that IIS apparently doesn’t set the REQUEST_URI server variable as expected. There are two ways to fix this issue, depending on how you are managing permalinks.

    The first way to fix this issue is to replace
    $_SERVER['REQUEST_URI']
    with
    $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO']
    This step was contributed by Unsought Input. I believe this works if you have used the pathinfo php.ini method described here.

    The second way to fix this issue was contributed by Yonatanz and it is what worked for me. I am using the 404-redirect method to enable permalinks which can be found over at Keyboard Face. This technique should also work for isapi_redirects. All you need to do is replace
    $_SERVER['REQUEST_URI']
    with
    $_SERVER['SCRIPT_NAME'].$_SERVER['QUERY_STRING']

  3. Copy wp-content/plugins/wp-cache/wp-cache-phase1.php to wp-content/advanced-cache.php (not really sure why this isn’t simplified by the author).
  4. Open the standard wp-config.php file and add define('WP_CACHE', true);
  5. Now comes the tricky part:

    open wp-content/plugins/wp-cache/wp-cache.php in your favourite text editor. Search for the wp_cache_add_pages function and change the function code like this:

    add_options_page('WP-Cache Manager', 'WP-Cache', 5, 'wp_cache/wp_cache.php', 'wp_cache_manager');

    The reason the original code doesn’t work is that the original __FILE__ resolves to wp_cache\wp_cache.php which some browser eat and convert to wp_cachewp_cache.php, which doesn’t exist.

  6. The second problem is that WP-Cache checks for installation step 2) in a windows-incompatible manner. Search for the wp_cache_check_link function. Change the first three lines after the variable declaration in this way:

    # if ( basename(@readlink($wp_cache_link)) != basename($wp_cache_file)) {
    # @unlink($wp_cache_link);
    # if (!@symlink ($wp_cache_file, $wp_cache_link)) {
    if (!file_exists($wp_cache_link)) { {

  7. Finally, if you are running an older version of WP-Cache, open wp-content/plugins/wp-cache/wp-cache-phase2.php and search for ob_end_clean(); and replace with ob_end_flush();. Without this change the cached page contents are not written back when the page is initially cached. It’s unclear to me if that works under *nix, I assume it couldn’t. This appears to have been fixed in WP-Cache 2.1.1.
  8. That’s it- you’re done. Now goto Options/WP-Cache and turn caching on.

3 comments

  1. I had the same problem. Tried this lots of times in the past but for some reason never could get it to work. Everyone gives instructions to add the define(‘WP_CACHE’, true); to your wp-config.php. I had manually added it at the bottom of the file. After removing that I was able to go to the admin and Disable, then Enable the cache and everything started working.

    Peace!

Leave a Reply

Your email address will not be published. Required fields are marked *