Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Concurrent Users

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
I found a little snippet for Global.asa code that is supposed to count concurrent users and it seems to work except the count is not accurate: if I'm the only one using the site (on my local system), the count is "1" as it should be, but if I open a second browser, the count is "3" which seems to grow as I open more browsers until suddenly it seems to match what's open. I do not quite follow how this code works but maybe someone can help shed some light on it for me. Actually I don't need the "visits" part but removing it seems to crash the whole thing.

[tt]Sub Application_OnStart
Application("visits") = 0
Application("Active")= 0
End Sub

Sub Session_OnStart
Session.Timeout = 1
Session("Start")=Now
Application.lock
Application("visits")= Application("visits") + 1
intTotal_visitors = Application("visits")
Application.unlock
Session("VisitorID") = intTotal_visitors

Application.lock
Application("Active")= Application("Active") + 1
Application.unlock
End Sub

Sub Session_OnEnd
Application.lock
Application("Active")= Application("Active") - 1
Application.unlock
End Sub[/tt] Don
don@pc-homepage.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT/2000 (only when I have to!)
 
Hi,
You can't get this fixed this way (this is a simple active session count, not a unique visitor count). This is because a session will only time out after the Session.Timeout which is defaulted to 10min. So, when you open up a new session, it will increase. Even after you close the browser, the active session is still not dropped until the session.timeout period. This is also a strong reason why large sites (heavy traffic) are advised NOT to use session because each variable you placed in the Session object will take up space for at least 10minutes (10min after the user drop the session) and this will kill your memory on your server like crazy ...

So there is no 'EXACT' way to track the number of active clients (because the system don't know if the client is still connected after the end of the ASP page execution). It can only give you the estimate (ie, the time out).

Alternatively, you can give the count of actively executing pages by forcing a Session.Abandon on each ASP page. This will will ensure that the Sesssion_OnEnd event is fired everytime. However, this has an adverse effect on other session variables that you may have set ...

Hope this helps. ~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
Visit --> for (Replica) Watches, Pen, Handbags, Hats, Jerseys and more ... at prices that makes your code spin ...
~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top