简体   繁体   中英

chatrooms online users list implementation

I have to implement a chatroom with list of users in that room. I will do this with mysql+memcache. The array of users in room will be updated, when a user enters or leaves a room. But, we have autologout on the site, so inactive users are logged out when they are inactive for 30 minutes, and this is a problem now:

I can't refresh the list of users in room, because i don't know, when the autologout occurs. We don't have script for logging out inactive users. In the main online list, they are listed like this: SELECT * FROM users WHERE last_fresh > 1352415100 Our online list don't show users are inactive for 30+ minutes, but I can't store and update the last_fresh time in the array of users in room every time, when every user on that room refreshes the page.

How can I do that?

Depends if you want to push or pull the changes. Pushing is always preferred but will take something like nginx-push-module or some other server side technology. Pulling is definitely easier, but will create more overhead.

If you are pulling, you can poll the list of logged in users and refresh the room list based on the data. An ajax call that updates the view will accomplish this. Look at jQuery or prototype.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM