Forum Moderators: phranque

Message Too Old, No Replies

How many visitors are online.

Is there a Script that says "X many visitors are online" on my site?

         

uhwebs

6:44 pm on Jan 21, 2006 (gmt 0)

10+ Year Member




I have sometimes seen something on a site like, "X many people online". I am wondering how I can get something like that for my site? A script that tells how many people are browsing your site at any given time?

blue_eagle

9:29 pm on Jan 21, 2006 (gmt 0)

10+ Year Member



search for online visit counter you should be able to come up with many php scripts

celgins

9:41 pm on Jan 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you're running a dynamically driven site (ASP, PHP), you should probably use session variables to calculate the number of users currently using your site.

For example in ASP, you would use the "Session_OnStart" and "Session_OnEnd" functions in your global.asa file.

krod

2:29 am on Jan 22, 2006 (gmt 0)

10+ Year Member



If you use phpbb software, you can integrate the 'whos online' in your main website.

Matt Probert

12:00 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In Perl, on a Linux server try (within a full program):

open(FILE,"netstat -na ¦ grep ^tcp ¦ wc -l ¦");

while(<FILE>)
{
print "SYSTEM STATUS:<br>$_ users online";
}
close(FILE);

This will return the number of currently open sessions (that will include AOL users where they open numerous sessions to access images), but it's close enough!

Matt

MichaelBluejay

2:38 pm on Jan 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Of course, unless I'm mistaken, the most you can know about a user's status is the last time they requested a page. Once the page has been delivered to the user's browser there's no telling whether they leave immediately or spend the next hour contemplating the page they just got. At some point you have to decide how old a page request counts as an "active" user. (5 minutes? 30 minutes?)

zCat

3:23 pm on Jan 22, 2006 (gmt 0)

10+ Year Member



netstat -na ¦ grep ^tcp

This shows the number of TCP connections active, it will not neccessarily correspond to a meaningful number of "site users" from the output. Depending on the system it will also include TCP connections to databases, proxy servers, SSH sessions etc.

You could parse the output to extract only HTTP sessions, possibly with a particular state (ESTABLISHED?), which might give a reasonable ballpark figure. Or it might not, depending on how you define "visitor" (e.g. the figure would include any bots).