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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of website hits at a time 3

Status
Not open for further replies.

kurie

Programmer
Jun 4, 2008
170
ZA
hi all,
does anyone know how to write code to view the number of current users currently accessing a website.
or any information on how to do that.

thanks very much

 
Hi

While HTTP is stateless protocol, such statistic information is not an exact science.
[ul]
[li]What are "current users" ?[/li]
[li]What means "currently accessing" ?[/li]
[/ul]
Usually a user is a registered and logged in visitor. Probably you can query such information from your user database.

Usually an access is a request and its response. That means between 0 and [tt]max_execution_time[/tt] seconds.

But I think you want the number of request made by any kind of visitors in the latest, let us say, 5 minutes.

For this you will have to make kind of log of them. Either in a file or a database. There you will put the time of request and some identifier. The time of request will help to count only the requests made in the last 5 minutes and optionally to discard outdated records. The identifier will help to count each visitor's request only once in case he made multiple requests in the last 5 minutes. The simplest identifier would be the visitor's IP address, but for preciser counting a session identifier would be better.

Feherke.
 
This probabbly depends on what platform your on.
If you are using sessions you could perhaps count the session files in the session directory or if your using mysql on each page do a show processlist which will show how many open connections to the server there are ,which may give a rough indication for you. You might be able to ask apache what it thinks is going on or you might write some logging code into your app.
The major problem is that you might thing a user is connected when in fact he might have closed the browser and gone elsewhere. So in a home rolled app you might update a timestamp assiociated with each session and then do a count of sessions that have been hit in the last x minutes.
I'm sure lots more suggestions will follow.
 
what i want is somethink like "online users on skype" and other chat websites.
by current i meant public users who have opened the website, it doesnt have to be an absolute excact figure.
thansk guys, i will do some research aswell
 
strictly speaking i agree with feherke. http is a stateless protocol.

however you can mimic state through javascript interaction with the server (AJAX). just fire the ajax call of at a frequent interval (30 seconds perhaps).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top