Forum Moderators: open

Message Too Old, No Replies

Counting current visitor sessions in Classic ASP

not really important, but nagging...

         

dataguy

10:10 pm on Jul 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've always thought it would be a user-appreciated novelty to be able to display how many visitors were currently on my web sites. I've seen scripts which add and subtract from an application variable at Session_OnStart and Session_OnEnd routines. This wouldn't work for me as some of my sites span several servers, so I decided to try counting visitor sessions by adding and subtracting values in a database table.

At the beginning of this past week I decided to start playing around with the idea. I set the value to '0' during Application_OnStart, add 1 to the value at Session_OnStart, and subtract 1 at Session_OnEnd.

The problem is that after a few hours, my value goes negative. Initially the number goes up close to 2,000 within the first 20 minutes, and then varies until it goes negative. This is a pretty large site which averages about 30,000 unique visitors per day.

Any ideas on what is going wrong?

aspdaddy

11:23 pm on Jul 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using applicatioon pooling? sounds like you are recycling the pools and the values resetting to zero each time ther pool recycles. I only recycle once a day when traffic is at the lowest.

wsrinivas

10:03 am on Aug 11, 2006 (gmt 0)

10+ Year Member



Hi best thing is to use header include file

and in this file upgrade your visitor counter in a text file or a database value

this is what i do for our website, but i have gone a bit further i also cpapture, what urls visited and visited and what is the referrer.

Regards
Sri

carlb007

12:20 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



ive mistakingly just made a new topic about this without reading down the list.

But how exactly does an include file help? how can u add 1 to a database each time a page is loaded? And when a user leaves the site how do you then subtract 1 from the text file or database without using a session on end application variable?
Doesnt make any sense to me.

The comment about the pooling seems more logical.....but when the pool is reset should that not cause the global to reset back to an application on start status?
Im also sceptical because whenever the pool resets on our server it usually results in all member being logged out, and our counter goes visibly wrong without ever witnessing a logout....

aspdaddy

6:11 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



but when the pool is reset should that not cause the global to reset back to an application on start status

Does application on_start fire up when pools are recycled? I thought it only did when you reeboot/restart IIS.

When the pool recycles all application data is lost but as session data is persited using cookies maybe the sessions stay open. Then when the session ends it goes negative.

carlb007

11:29 am on Aug 24, 2006 (gmt 0)

10+ Year Member



hmm. You pose a good question there daddy. My understanding is indeed that global is only reset when either you replace the global file or iis/server is restarted.

It all gets a little confusing now though. If the global variable DOES get reset on the pool, and the logged in sessionID's do keep persisting, surely that makes it almost impossible to build a counter into any ASP website?
Ive never read anywhere else users having such a problem build such a simple item - but perhaps that is because our site is busy and causing the pool to recycle much more often than most other sites tend to and so is more noticeable.

Assuming your theory is correct (and im thinking you could well be!) how on earth can i get around this flaw, aside from not allowing the pool to reset at all?
Logged in members go into a database table so that count is always correct as they are only erased from that table when the ending sessionID matches with the one in the table. Is there a way to count all current SessionID's currently active, and then i can simple subtract the member count from that count....

going to research this some more now. Thank you for your help :)

carlb007

12:39 pm on Aug 24, 2006 (gmt 0)

10+ Year Member



Dataguy ..... ive found an excellent solution to our problems after a bit of research:

[aspfree.com...]

use that script there. It works flawlessly for me so far. Good luck with it!

kswest

12:34 am on Sep 7, 2006 (gmt 0)

10+ Year Member



You said this is on multiple servers ...

Everything is fine on server 1 then server 2 gets its first request and resets the count to 0 when it really shouldn't be.

What you need to do is get rid of the Application_OnStart setting the value to 0.