Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
11-15-2010, 03:47 PM #1
- Join Date
- Nov 2010
- Thanked 0 Times in 0 Posts
Hi I am working on a chat application and am a bit stuck...In the database I have a field status which is set 1 for online and 0 for offline (PHP/MySQL)(at time of logging in/out), this shows the users status on a webpage. What I need is to know if there is a way I can set a timer so that if the user has been inactive for X amount of time, the database is auto updated and user is offline (1 set to 0).
Thanks for any help I recieve
11-15-2010, 05:23 PM #2
- Join Date
- Jun 2002
- London, England
- Thanked 2,531 Times in 2,509 Posts
Last edited by Philip M; 11-15-2010 at 07:17 PM.
11-15-2010, 08:47 PM #3
There's actually a much better and easier way for something like a chat application: Instead of just an on/off flag in the DB, use a DATETIME field.
Every time the user makes a chat post, update that field to the current time. (You can also update it periodically if the user has some other activity indicating they are still "on" the site, of course.)
And now, to find users who are online, you simply SELECT all those whose last update in that field is with the last NN minutes, where you get to choose what NN is.
If you put an index on the field, this is just as efficient as selecting for a True/False "is online" field.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.