开发者

Should I use txt file or store in database in module "who is online"?

开发者 https://www.devze.com 2023-04-10 23:58 出处:网络
I have a project which must check who is online. I\'m thinking of two ways to store data: 1. Save last access time of user in database, get user online from query.

I have a project which must check who is online. I'm thinking of two ways to store data: 1. Save last access time of user in database, get user online from query. 2. sav开发者_StackOverflowe last access time of user, other info in file, get file, delete timeout user. Every time we want to get online, read this file.

I wonder which way is better? Or other better solution? Any suggestion?


Go with the database. Why would you subject yourself to all of the hardship and inefficiencies of coming up with your own file format, then reading it and parsing it every time you wanted to check something?


With most of the database managers, doing a query in a database is faster than reading and processing a file.

If you're really concerned about the performance, you can create another table where you save the user ID as a foreign key and its last log-in time. And when you do a query, you can also delete the users on that table who haven't log-in in a certain amount of time.


use memcache with the ttl set to your timeout threshold then you don't need to worry about deleting them manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消