设计问题:如何显示在线用户数? [英] Design Question: how to show number of users online?

查看:66
本文介绍了设计问题:如何显示在线用户数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计划开发 LAMP 网络应用程序.我可以使用哪些一般策略来显示当前登录到我的站点的用户数量?我希望能够准确地显示诸如当前有 1000 个用户在线"或用户 John Doe 当前在线"之类的内容.

Planning to develop a LAMP web application. What general strategies can I use to display the number of users currently logged in to my site? I want to be able to accurately display something like, "There are currently 1000 users online" or "User John Doe is currently online".

推荐答案

将涉及到一个数据库.因此,每次有人登录该站点时,您都​​可以在用户表中为 last_login 设置一个字段.然后可以有一个脚本对该用户的表进行查询,以计算最后 x 时间内 last_login 的行数.最好缓存它并每隔 z 时间重新填充这个缓存,然后从这个缓存中提取,而不是每次请求对用户的表运行查询.所以数据库+某种缓存系统.

A database will be involved. So every time someone logs into the site, you can have a field in a user's table for last_login. And then there can be a script that does a query against this user's table to count the number of rows last_login within the last x amount of time. It may be good to cache this and repopulate this cache every z amount of time, and then pull from this cache as oppose to running a query against the user's table every request. So database + some kind of caching system.

这篇关于设计问题:如何显示在线用户数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆