Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement taking a website offline?

Don't need to do this right now but thinking about the future...

What would be your method to take a website "offline" for a little bit through a custom coded cms? Meaning give the capability for an admin to login into an admin panel, type a message into a box, and submit the form. That message would then display rather than any other page to any user, unless the user is an admin.

I have done this before and used a if xml file exists then load the content from the xml file and puts a construction background behind the message with a login box that only allows admins to log in. When the admin would type the message into the box it stored the text into the xml. When they brought the site "back to life" it would simply delete the xml file.

The only problem was that once the site grew, it took more hits and checking for a file exists every page load was becoming slow. Anyone have a better solution for me?

Thanks.

like image 352
Capt Otis Avatar asked Feb 26 '23 07:02

Capt Otis


1 Answers

Assuming this is on Apache.

If at all possible, I'd recommend doing this using a .htaccess file that re-routes all requests to a "site is down" message.

Something like:

RewriteRule (.*) /downmessage.php [L]

(note that any image resources will be redirected, too)

Compared to a PHP-side flag check and offline message, this is faster, plus it has the huge advantage that resources like uploaded images and style sheets are no longer reachable either - which they otherwise might be, through cached files, URLs, Google Images hits...

In a PHP-based "offline" mechanism where those resources are not blocked, the fact that some resources are still reachable if somebody knows the URL is very difficult to explain to users ("but we took the site down, didn't we?") and if the site gets taken down because of legal problems regarding a published image (can happen to everyone!), the image could still be reachable without the site owner knowing.

The downside to this is that it requires the mod_rewrite module on the server, and PHP needs to have write access to the .htaccess file: Both not always the case.

However, while this method has its advantages, the basic premise of your question is worth looking at before implementing any changes. You say that the check for the takedown XML file is taking too much time. I don't think that is the case. file_exists() checks are cached internally, and should not cause any noticeable slowdown even for very many requests. The average Drupal or WordPress page loads dozens of include files on every request. A single file_exists pales in comparison.

like image 119
Pekka Avatar answered Mar 06 '23 03:03

Pekka