Most efficient way to update who is in a chat room?
Posted: Fri Jan 16, 2009 9:36 pm
First and foremost here is my chat room which has come a long ways since the beginning of this month (if you are viewing this as an archive and my site is Version 2.9 or higher then check my main site)...
http://www.jabcreations.com/members/
Sign in as test/test and then enter the chat room. Feel free to open two browsers and sign on both as test/test if no one else is there to emulate a small conversation. Chat room commands are listed in this thread (including some Linux commands for you console lovers)...
viewtopic.php?f=2&t=93576&start=15#p511622
Any way tonight I'm working on the members list of who is currently signed in and in the chat room. I have a MySQL table called chat_list so I can add another column for multiple chat room support later if I need to. Any way right now it's pulling some odd data so it looks like it sort of works. The thing that concerns me is minimizing server load as much as possible so writing to the database is something I want to be restrictive about while also not going 10MPH if I can do 45MPH.
I figure the variables might include a maximum number of people in the (or a) chat room, how often AJAX sends a "I'm sign in the chat room" signal to the server, and other possible things I may not even be aware of at the moment.
One thing I've done with the chat room is maximize what I can off load to the client. In example when I add censorship for harsh cursing it'll be the client that executes the regex when the message is received. One thing that just cross my mind is actually having the chat room somehow remembering who is in the chat room at the client when their name is updated...and maybe assign some sort of count down, say one minute (not aiming for accuracy just yet with the concepts). Then I could create an array of lurkers and only have the server request those in the SELECT query. The issue then I suppose would be that if you've been in the chat room for four hours and it does not write once say every ten minutes then if the initial request for who is in the chat (date/time being between A and B) then someone who is in the chat will not appear to be online. I'm just trying to show examples of what I've considered.
Right now I'm working on having the client send an "I'm online" UPDATE query once every X seconds. I figure I can also send a kill signal for the client though I'm not sure how I would do that...I could probably just have MySQL set the DATETIME to all zeros and it could just be overwritten next chat session (to avoid overhead I suppose). That way the worst case scenario would be to think someone is online though they simply time out after a minute. How to determine when someone has timed out (with a timed PHP function?) is beyond me at the moment though I know I'll need to program that too somehow. Having it show them leave the chat room won't be difficult if it's not a time out though.
Thoughts please?
*EDIT* I decided since I am not aware of when a message happens to implement a sound if a new message occurs...if you don't hear the sound then wait a minute or two though I am "around" in my chat.
http://www.jabcreations.com/members/
Sign in as test/test and then enter the chat room. Feel free to open two browsers and sign on both as test/test if no one else is there to emulate a small conversation. Chat room commands are listed in this thread (including some Linux commands for you console lovers)...
viewtopic.php?f=2&t=93576&start=15#p511622
Any way tonight I'm working on the members list of who is currently signed in and in the chat room. I have a MySQL table called chat_list so I can add another column for multiple chat room support later if I need to. Any way right now it's pulling some odd data so it looks like it sort of works. The thing that concerns me is minimizing server load as much as possible so writing to the database is something I want to be restrictive about while also not going 10MPH if I can do 45MPH.
I figure the variables might include a maximum number of people in the (or a) chat room, how often AJAX sends a "I'm sign in the chat room" signal to the server, and other possible things I may not even be aware of at the moment.
One thing I've done with the chat room is maximize what I can off load to the client. In example when I add censorship for harsh cursing it'll be the client that executes the regex when the message is received. One thing that just cross my mind is actually having the chat room somehow remembering who is in the chat room at the client when their name is updated...and maybe assign some sort of count down, say one minute (not aiming for accuracy just yet with the concepts). Then I could create an array of lurkers and only have the server request those in the SELECT query. The issue then I suppose would be that if you've been in the chat room for four hours and it does not write once say every ten minutes then if the initial request for who is in the chat (date/time being between A and B) then someone who is in the chat will not appear to be online. I'm just trying to show examples of what I've considered.
Right now I'm working on having the client send an "I'm online" UPDATE query once every X seconds. I figure I can also send a kill signal for the client though I'm not sure how I would do that...I could probably just have MySQL set the DATETIME to all zeros and it could just be overwritten next chat session (to avoid overhead I suppose). That way the worst case scenario would be to think someone is online though they simply time out after a minute. How to determine when someone has timed out (with a timed PHP function?) is beyond me at the moment though I know I'll need to program that too somehow. Having it show them leave the chat room won't be difficult if it's not a time out though.
Thoughts please?
*EDIT* I decided since I am not aware of when a message happens to implement a sound if a new message occurs...if you don't hear the sound then wait a minute or two though I am "around" in my chat.