問題描述
我要求我的網站始終顯示當前在線的用戶數量.例如,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.
這篇關于跟蹤當前在線用戶的最佳方式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!