WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With our website, we want to make it so that if the site is about to go down, it instead displays a custom 503 (based on a server load limit set by us). Is there something that can handle this that is already built in, or a plugin that might help?

I know manual switching maintenance mode plugins are available but if the site hits heavy traffic they will get taken out.

share|improve this question
I think this is more of a Server Fault serverfault.com question :) – BandonRandon Apr 6 '11 at 5:31

Twitter and other high-volume sites probably do this one layer ahead of the servers. Probably with a load balancer that can detect the server load over all servers and if the load is too high (when machines stop replying) they redirect traffic to a server that returns only the "fail whale" page.

This answer on Stack Overflow suggests to look at sys_getloadavg() and display an error when it is too high (and "too high" should be defined by trial and error). I would do this in the main index.php file that "boots" WordPress, to get a quick exit and not put more load on the server.

share|improve this answer
using sys_getloadavg perhaps would work better, than mine. – petermolnar Apr 6 '11 at 14:16
@cadeyrn: I assume it is the same data, but the direct system call avoids the detour with the "fake" file. And I think it works on more platforms (not all platforms use /proc/loadavg). – Jan Fabry Apr 6 '11 at 14:21
I thought the same, that's why I think too using the function is better. – petermolnar Apr 7 '11 at 12:36

If your system is on linux, you can read the actual server load from /proc/loadavg

For example:

$load = reset ( explode ( ' ' , file_get_contents('/proc/loadavg') ) );

if ($load > 3.14 )
    // load too high, 
    header('HTTP/1.1 503 Service Temporarily Unavailable');
    header('Status: 503 Service Temporarily Unavailable');
    header('Retry-After: 60');

EDIT: added header method lines.

share|improve this answer

You can customize message for when database is down by drop-in db-error.php in wp-content directory.

But if PHP is down I do not think there is anything that WP or its plugin would be able to do. It is better to ask your hosting how can you customize server's 503 page.

share|improve this answer

In your .htaccess file, add this line:

ErrorDocument 503 /error503.html

Then make an error503.html file in the root of the site that has your custom stuff in it.

This may or may not work depending on how your hosting is configured.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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