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.
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 mainindex.php
file that “boots” WordPress, to get a quick exit and not put more load on the server.If your system is on linux, you can read the actual server load from
/proc/loadavg
For example:
EDIT:
added header method lines.
You can customize message for when database is down by drop-in
db-error.php
inwp-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.
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.