define( 'WPCACHEHOME', '/srv/www/www.ichilton.co.uk/html/blog/wp-content/plugins/wp-super-cache/' ); //Added by WP-Cache Manager Using the W3 Total Cache WordPress Plugin with Rackspace Cloud Files | Ian Chilton
Home > WordPress > Using the W3 Total Cache WordPress Plugin with Rackspace Cloud Files

Using the W3 Total Cache WordPress Plugin with Rackspace Cloud Files

The W3 Total Cache plugin for WordPress is a bit of a one-stop-shop performance plugin which includes features like Caching, Minifiying and CDN capability.

Rackspace Cloud Files, who partner with Akamai to provide CDN functionality is supported but unfortunately didn’t work for me and was failing to upload the files. It will successfully create the container and show ‘Test Passed’ when clicking the test button but when actually using the upload buttons, every file just showed ‘Unable to create object’.

After some debugging (got it to e-mail me the output of $exception->getMessage();), I managed to track down that it was trying to write the files with a leading / and Cloud Files didn’t allow this. So, I put the following fix in place:

In wp-content/plugins/w3-total-cache/lib/W3/Cdn/Rscf.php, locate the upload function, as follows:
function upload($files, &$results, $force_rewrite = false) {

Find the line which loops round the files:
foreach ($files as $local_path => $remote_path) {

Insert the following code after that – this checks for a leading / and strips it off if present:
if (substr($remote_path, 0, 1) == '/')
$remote_path = substr($remote_path, 1);

While I was there, I also modified the plugin to support the UK Cloud Files and the new URL format:

In wp-content/plugins/w3-total-cache/lib/CF/cloudfiles_http.php, find the following:
$path[] = "https://auth.api.rackspacecloud.com";

Change it to the UK API URL:
$path[] = "https://lon.auth.api.rackspacecloud.com";

In wp-content/plugins/w3-total-cache/W3/Cdn/Rscf.php, find the following in the get_domains function:
$domain = sprintf('%s.cloudfiles.rackspacecloud.com', $this->_config['id']);

and replace it with this:
$domain = sprintf('%s.rackcdn.com', $this->_config['id']);

then find this in the create_container function:
if (preg_match('~^https?://(.+)\.cloudfiles\.rackspacecloud\.com$~', $container->cdn_uri, $matches)) {

and replace it with this:
if (preg_match('~^https?://(.+)\.rackcdn\.com$~', $container->cdn_uri, $matches)) {

Please note, the version of W3 Total Cache I was using was: 0.9.1.4b (development version) so these changes may not be required or work in newer versions.