跟踪当前在线用户的最佳方式

Best way to keep track of current online users(跟踪当前在线用户的最佳方式)

本文介绍了跟踪当前在线用户的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求我的网站始终显示当前在线的用户数量.例如,35741 个用户当前在线".这不是基于登录,而是基于当前有多少用户在我的网站上.我已经尝试为此使用会话开始/会话结束,但是会话结束并不可靠.因此,我得到了夸大的数字,因为我的会话开始添加数字但会话结束不会删除它们,因为它不会触发.

I have a requirement that my site always display the number of users currently online. For example, "35741 Users Currently Online". This is not based on a log in, simply how many users are currently on my site. I have tried using Session Start/Session End for this, however session end is not reliable. Therefore I get inflated numbers, as my session start adds numbers but session end doesn't remove them because it doesn't fire.

无需从中收集其他信息(报告等),只是要求显示数字.非常简单的请求变成了一笔巨大的交易.任何帮助表示赞赏.

There is no additional information to be gathered from this (reporting, etc), it's simply requested that the number show up. Very simple request that's turning into a huge deal. Any help is appreciated.

我应该说明我也尝试过为此使用数据库.包含会话 ID 和最后一个活动列的简单表.每次点击页面时,我都会检查会话是否在我的数据库中.如果没有,请插入.如果是,请更新活动时间.然后我运行一个程序来扫描数据库,寻找在过去 20 分钟内没有活动的会话.这种方法似乎杀死了我的 SQL 服务器和/或 IIS.不得不重启网站.

I should specify that I have also tried using a database for this. Simple table that contains a session ID and a last activity column. With each page hit, I check to see if the session is in my database. If not, insert. If so, update with activity time. Then I run a procedure that sweeps the database looking for sessions with no activity in the last 20 minutes. This approach seemed to kill my SQL server and/or IIS. Had to restart the site.

推荐答案

最好的方法和你一样,但通过活动超时.如果给定的会话在 5 分钟左右的时间内没有访问页面,您可能会认为它们不再处于活动状态.

Best way is like you do, but time it out via activity. If a given session doesn't access a page within 5 minutes or so, you may consider them no longer active.

这篇关于跟踪当前在线用户的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:跟踪当前在线用户的最佳方式

基础教程推荐