PDA

Click to See Complete Forum and Search --> : Q: Online Visitor algorithm?


Visual Basic.Net
Jan 21st, 2009, 02:51 AM
hi. what is the online users alogorithm using in forum like vb and phpbb?
I thought to include in each page of the site, a page that make update into the sql every 5 minutes for a record containing IP of the visitor and the time of update. and in the page of viewing online user I see if the IP time is more than 5 minutes, I should not display it, and delete it.

is it correct? or there is another better way?
thank's for advance

kows
Jan 21st, 2009, 05:30 AM
well, if I understand what you're trying to say, you're at least on the right track. the easiest way I've found is to have a field in your accounts table named something like "last_activity," which would store a timestamp. you would have a function or include that was on every relevant page that updated this timestamp for the current user whenever the page was visited. then, to display the users active in the last 15 minutes, you would simply need to query:
$sql = "SELECT username FROM accounts WHERE last_activity>=" . (time() - (15*60));

Visual Basic.Net
Jan 21st, 2009, 06:05 AM
but if I just put the code in each page. if you opened a page and made it open without activity the system will count you as offline. while if i puted something with java like a timer to update the timestamp in the database automatically each 5 minutes for example, that will count the ones who opened the page without activity. I don't know. please if any body have a better idea share it with us
thank's kows

ngreenwood6
Jan 21st, 2009, 07:17 AM
kows is right most websites check either the database or a cookie for you last activity. Everytime you visit a page it updates your last activity to the current time. I don't know why you would want to update it if the user isn't active. That would kill alot of resources especially if someone just left the website running on their computer and wasn't actually browsing. That is why they do it they way it is done so it actually shows ACTIVE users. By the way I think you meant javascript not java. You can do it with javascript but I think that would be a waste of time and resources.

edit: if you wanted to do it with javascript you could just set it to update the database or a cookie every 5 mins. not really any difference.

Visual Basic.Net
Jan 21st, 2009, 07:39 AM
No, I want to update it every 5 minutes to prevent wasting of resource!!
because your method is updating every time the user load anypage and that will make big traffic. while what I want to do is updating the database record every 5 minutes until if the user load many pages, the system will update the online record only every 5 minutes and once. but I don't know how to do it, because the counter in one page will differ from the counter in the other page (suppose that the counter will be made in javascript). because of that I want to see if there is another more efficient way or at least how to implement my idea.
thank's :)

ngreenwood6
Jan 21st, 2009, 02:36 PM
Either method in my opinion will take up the same resources. The reason I say that is because on every page you will still have to check to see if it has been five minutes or not. An alternate solution would be to do it through sessions instead of the database. Eveytime they go to a new page check/update a session variable. That would probably use less resources than querying the database and then comparing.

kows
Jan 21st, 2009, 07:14 PM
the method I described really doesn't use many resources at all. you're trying to make things much more complicated than they need to be. since you're already using user accounts, it's just one extra query to the database to update that user's last activity. it will not create "big traffic" or even have a noticeable server load.

Visual Basic.Net
Jan 22nd, 2009, 03:15 AM
Either method in my opinion will take up the same resources. The reason I say that is because on every page you will still have to check to see if it has been five minutes or not. An alternate solution would be to do it through sessions instead of the database. Eveytime they go to a new page check/update a session variable. That would probably use less resources than querying the database and then comparing.

So, your idea is to checking the time from the session, and when it reach 5 minutes from the last update I update the database again.
thant's seem good :thumb:
if any body have better idea please share it with us
thank's ngreenwood6 :wave:

Visual Basic.Net
Jan 22nd, 2009, 03:20 AM
the method I described really doesn't use many resources at all. you're trying to make things much more complicated than they need to be. since you're already using user accounts, it's just one extra query to the database to update that user's last activity. it will not create "big traffic" or even have a noticeable server load.

I don't know. it seem that it produce huge traffic by update the database every time the user access any page.
So, in each page and every time the user enter or update the page. it will do 2things:
1) insert
2) retreive

Imagine if we have 60000hits for example?! alot at the same time!

kows
Jan 22nd, 2009, 03:39 AM
to set the record straight -- you won't be inserting into the database, you'll only be updating an existing record.

SQL queries don't produce a lot of server load -- they were built this way. websites that have an average of 100,000 hits per day do not need super beefy servers to handle the traffic. even websites that track very simple statistics like unique and total views query the database at least once or twice per page view just for this type of stat tracking. this is normal. most forum software usually has at least 10 SQL queries per page -- I'd be surprised to see any complicated software have less.

Visual Basic.Net
Jan 22nd, 2009, 05:34 AM
to set the record straight -- you won't be inserting into the database, you'll only be updating an existing record.

SQL queries don't produce a lot of server load -- they were built this way. websites that have an average of 100,000 hits per day do not need super beefy servers to handle the traffic. even websites that track very simple statistics like unique and total views query the database at least once or twice per page view just for this type of stat tracking. this is normal. most forum software usually has at least 10 SQL queries per page -- I'd be surprised to see any complicated software have less.

So, I will use this method. Thank's alot bro :wave: