views:

279

answers:

6

I'm wonder how people are kicking people out or blocking access to a site when you want to do an upgrade and you have users that are logged in.

My one thought is to just put a bool setting in a global file (such as the settings file) for whether or not the site is unavailable. True is available, while false is unavailable. When false, the next time the user attempts to access the site they will either be logged out or just presented with an unavailable message.

There are 2 issues I can see with this method:

  1. If users are just finishing filling in a long form or writing a large portion of text (like a new question or answer on SO), as soon as they submit the form, they'd lose that information. (Can't always save it, because there maybe DB changes for that table or code may have changed already.)

  2. Possible: On a busy site, editing the global file if it's more than a couple lines it might cause PHP parse errors if that page is loaded while it's partially uploaded or while saving. There might also be locking issues on the file, depending on the configuration.

Another option is to have a field in the database with the same setting. At the moment, I don't generally have a table for settings, so this would be the only thing in the table, but I could see it being faster as it avoids the second problem.

Is there something that you've used that worked well or any other ideas?

I'm working with LAMP.

+1  A: 

What about just not allowing new users to log in, and monitor the number of logged in users until it is reaches 0, and then you can upgrade?

slolife
Good idea, but what about users that don't log out (therefore updating their db record) and this could also take a very long time on a busy site...possibly never.
Darryl Hein
even with a user timeout limit, it's impossible, I think!
Sepehr Lajevardi
Okay, seems like you could pick a reasonable amount of time that if you haven't had a request from a user, they are considered logged off (1 hour, 2 hours). But maybe not in your case.
slolife
+3  A: 

Inform the users in advance that your site will have downtime at a specified time and then perform the upgrade at your least busy hours according to your log files. Weekends work great for upgrading if your site is business critical to your users. A little downtime on a Sunday morning at about 3am probably isn't going to anger too many users. Just make sure that you have everything you need in place before you do the upgrade so that you can minimize the downtime. You might even consider doing a dry run on a test server.

VirtuosiMedia
Yes, but "Least busy" still indicates there could be users using the site.
Darryl Hein
Sure, but they've been warned that it's about to go down.
ceejayoz
Weekends work great for upgrading if your site is business critical to your users. A little downtime on a Sunday morning at about 3am probably isn't going to anger too many users.
VirtuosiMedia
+3  A: 

You could implement a status field, perhaps an AJAX style one like the orange bar at the top of StackOverflow pages, that informs the users that the site will be going down in 10-15 minutes or what have you. You could also disable logins during that time. Then just bring the site down completely, do your upgrade, and bring it back on line.

BobbyShaftoe
Good idea and I've thought about that too. The reason I decided against it is with 1000s of users, pooling the user every, even 5 minutes starts to add up. It's also not a drop and go solution--takes a bit of work to add.
Darryl Hein
Just about anything non-trivial will require lots of changes. Actually, you could create a JS function and insert into all of your pages fairly easily, not manually. It wouldn't be as much load as you think. People usually change pages within 5 minutes anyway; this is less load than loading an
BobbyShaftoe
+8  A: 

As the first solution, we can use a .htaccess file to redirect (or rewrite url) users to a we're-updating static page:

RewriteRule ^updating.*$ $0 [NC,U,QSA,L]
RewriteRule .* /updating/ [NC,U,QSA,R=307,L]

If you need test the site before publishing the new updated version, you can attach a specific string to your user agent and then using these lines in .htaccess file will bring you the exception of blocking!

RewriteRule ^updating.*$ $0 [NC,U,QSA,L]
RewriteCond %{HTTP:User-Agent} !ABC [NC]
RewriteRule .* /updating/ [NC,U,QSA,R=307,L]

So, How to attach! using firefox, create a about:config key like this: general.useragent.extra.XYZ and evaluate it by "ABC" or something, and you're done! The user agent tip credits is belong to Sohail Rashidi of iDevCenter.

As you mentioned, the next alternative solution could be the using of a config flag. but for that user-fairplay-design case, you can check if there's a $_POST or $_GET array set, save the data in a user temp table (or a temp record, ofcourse) for his/her future uses.

Sepehr Lajevardi
A: 

If your system is session based, an easy way is to change the session name. The cookie name will change and nobody will get the new one until they log in again.

stunti
+1  A: 

This one is similar to Bobby's suggestion. The way I achieved the same sort of thing is to put a couple of values in to a "config" table in the database, one is the date/time to take the system down, and the other is a message.

Once the date field is not null, then block all logins, and on every page refresh, just use a javascript alert to display the message to users explaining that the site will be taken down in X minutes, for Y reason and should be back online in Z minutes. This is an annoying and in-your-face way to do it, but it's really quite important that they realise that they shouldn't start filling in a really long form.

Once it's after that maintenance start time, then boot all users on their next page refresh. ...except for admins, of course.

Getting all the clients to periodically poll the server to check for an impending maintenance period is overkill, IMO. If you do have a couple of pages which have really long forms, then perhaps add the AJAX polling just on those ones.

Having these sort of values in the database is easy to implement, is quite flexible, and is perfect for this situation.

nickf
Yeah, but I do use the polling method described in some apps and I actually use it for many different kinds of status updates, not just Maintenance. The effect of the polling vs non-polling is negligible. The request is short and most visitors make a new request within a few minutes anyway.
BobbyShaftoe