Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I don't know much about how super cache works, but I see that at the very least, I can find most of the pages of my site in the wp-content/cache/supercache folder. Now, if WordPress cannot connect to the database due to the MySQL server being down (as is the case right now), should it be showing an error message or should it be showing the cached pages?

I would think that it should work regardless of whether the connection can be made or not. Is there an option or a flag that I am missing?

Also, it looks like the main page of the site is not cached, while everything else is. Is there any way to deal with that? Obviously I can't do anything about that right now, since the database is down, but for the future?

share|improve this question

closed as off-topic by Mark Kaplun, toscho Sep 23 at 22:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

This is a response to your second question -- "Also, it looks like the main page of the site is not cached, while everything else is. Is there any way to deal with that?"

In your backend, go to Settings -> WP Super Cache and select the Advanced tab. Look for the section titled Accepted Filenames & Rejected URIs. If Front Page (is_front_page) or Home (is_home) is checked, uncheck it, and then click the Save button. That should allow your site's Front / Home page to be cached.

NB: This assumes you're using the WP Super Cache plugin, which I gather from the question's tags that you are.

(I haven't tested this, though, so your mileage may vary.)

share|improve this answer

Seeing as you already have a cached version of your site, I can skip the part that explains how to set that up and skip to the simpler stuff --the PHP stuff!

You want to insert the mysql_ping() function at the tippy top of your header.php file in your current theme (or child theme, preferably). It should look something like this:

<?php set_time_limit(0);

$conn = mysql_connect('localhost', 'mysqluser', 'mypass');
$db   = mysql_select_db('mydb');

/* Assuming this query will take a long time */
$result = mysql_query($sql);
if (!$result) {
    echo 'Query #1 failed, exiting.';
    exit;
}

/* If nothing still, take the user to the cache */
if (!mysql_ping($conn)) {
    header( 'Location: http://www.yoursite.com/new_page.html' )};
} ?>

Because the header function is in there, you want to make sure this appears before anything else, including an <html> or <body> tag.

share|improve this answer
    
Also, if this doesn't solve anything, let me take a look at your script. –  Jared Steffen Mar 19 '13 at 20:20
    
The problem is that I shouldn't need to manually redirect to the cache file (which is in /wp-content/cache/supercache). Even if I do, the links in each of the files go back to the regular site, and I don't want to have to do a redirect every time. It should just be able to find the file in the cache automatically. As for the script, I have no script. This is just done with the supercache plugin. –  Ed Marty Mar 20 '13 at 18:12
1  
In my site's .htaccess file, there is a block of rules that starts off with # BEGIN WPSuperCache and ends with # END WPSuperCache. A cursory inspection seems to bear out your theory that the redirection should happen automatically -- I see lines that indicate that if there's a file called %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html, that file should be served up (assuming the user's not logged in, etc). –  Pat J Mar 20 '13 at 19:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.