W3 Total Cache and Multi-DB - can't we all be friends?

I've seen several posts now on the forums where WPMU users are using/recommending W3 Total Cache for their WPMU installs over plugins like WP-Super-Cache in "half on" mode, for example.

I've been reading up on it, and I really like W3 Total Cache, because in addition to the regular object/page caching, it's set up for CDN and CSS/JS minification.

NOTE: My WPMU install is still pretty small (<100 blogs, but growing), and we're hosted on one of the pSek WPMU plans. And we've got multi-DB installed and working (16 DBs).

NOTE 2: We cannot use memcached or nginx while we're on pSek shared hosting.

Now, I'm trying to implement site-wide caching and a CDN (Amazon CloudFront w/ S3), but I've just learned that W3TC and Multi-DB don't work together, since they each require a 'db.php' file in /wp-content/


Has anyone gotten these two to work together? Any recommendations?

  • joshmac
    • Site Builder, Child of Zeus

    @Aaron, I've tried merging and it did not work at all. I am not sure why W3TC needs a db.php file, since it's contents has nothing to do with a database. @nickd32, maybe it would be best to have W3TC look for another file besides db.php.

  • joshmac
    • Site Builder, Child of Zeus

    I should mention that there is an alternative to being able to use this plugin.

    change lines 126, 128 and 146. Rename db.php to db-cache.php

    change line 2562. Rename db.php to db-cache.php

    Rename db.php to db-cache.php

    When this is done, upload the files to your server, activate the plugin, and the db-cache.php file will be created and the plugin will be looking at this file instead of db.php.

    The only downside is that you will need to do a manual upgrade when updates are loaded or it will over ride your changes and then over ride your current db.php file for multi-db.

  • Aaron
    • CTO

    Super cache is a much faster for front end caching if your server setup allows for it. It's main distinction is that it pre-gzips pages into static files and serves those via apache without even loading WP. And if your server is configured right (php as cgi) that can use MUCH less ram. W3 cache is like super cache's half on mode. My server results were around:

    WPMU no cache: 3 pages per sec.
    WPMU with PHP object cache (APC, xcache, etc): 10 pps
    WPMU with w3 cache or super cache half-on: 20-30 pps
    WPMU with Supercache full on after first visit and page cached: 1000-2000pps

    The issue is that super cache can cause a lot of compatibility problems if your site is not optimized to use it. It won't work with load balancing over multiple servers, and you have to be able to accept no dynamic content on the page for the 30min cache period. For example many plugins require the loading of php on every page load. Any dynamic content would need to be designed to use js and ajax to load dynamic content. An example would be an ad widget that only shows ads to certain visitors. You would need to rewrite that to run via js rather than php.

    Of course W3 cache's claim to fame is all the other tools it provides like CDN etc.

  • joshmac
    • Site Builder, Child of Zeus

    @nickd32, on one of my sites, I am using WP Super Cache and the other I am using W3TC. But only one of those sites is using a multi-db structure. At some point I am going to switch that site back to W3TC because I can't do without the CDN and W3TC seems to handle Buddypress better. But that is just my opinion.

    Also, I should mention that you will not be able to use the database caching feature due to the disbursement of your database. Other than that, the other options for W3TC work very well.

  • jdevalk
    • New Recruit

    Accounts aren't free to reply here as far as I can see, so my mate Frederick asked me to chime in here:

    @Aaron, as you will see in some press that came out yesterday, you're a bit mistaken about what W3TC can do: https://premium.wpmudev.org/blog/maximize-wordpress-and-buddypress-performance-with-w3-total-cache/ - as shown here: http://cd34.com/blog/scalability/wordpress-cache-plugin-benchmarks/ it's the performer and Frederick says that lots of things to go even further are just around the corner. Specifically, it's the only plugin that does, browser, server and application level caching. So there's really no one-to-one comparison possible right now.

    W/r/t Multi-DB, either compatibility for this plugin is planned for v1.1 or a replacement + support for Google MMM (http://mysql-mmm.org/) has been in the roadmap since last year. As stated in the forums, db.php is a "reserved" file name in WordPress so a name conflict exists for any plugin that wants to manipulate the database behavior.

    W/r/t BuddyPress, object caching and fragment caching is added to W3TC v0.9, which are perfect for BuddyPress. Meanwhile, disk basic / disk opcode / disk memcached caching methods for page caching all help your blog scale, not to mention database caching (which you can debug easily using debug mode to ignore important queries he may have missed) are very solid for now. Minify and CDN improve user experience reduce server load. So the object cache, based on discussions with Andy Peatling and John James Jacoby will be one of the keys here you can enjoy in the next release.

  • Barry
    • DEV MAN’s Mascot

    I currently use the WP Super cache with my multi-db set up and my own theme offloading CDN plugin.

    Did have a go at W3TC a short while ago and gave up pretty quickly, mainly because I run a multi-db system and just didn't have the time to get them working together.

  • johnnymestizo
    • HummingBird

    Renamed the one occurrence of db.php in the w3 files to db-cache.php

    At the end of the file /w3-total-cache/lib/W3/Plugin/DbCache.php

         * Change action
        function on_change() {
            static $flushed = false;
            if (!$flushed) {
                require_once W3TC_LIB_W3_DIR . '/Db.php';
                @$w3_db = & W3_Db::instance();

    Then finished the whole installation process of multi-db.

    Then, i get the whitescreen at tradr.com that redirects to


    Had to revert to backup.

    Any ideas?


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.