Page 1 of 1

Users online

Posted: Tue Aug 23, 2005 11:54 pm
by s.dot
Right now I have my users online set so that whenever they actively click a link it will update their 'timelastactive' in the database. Then I see whos been active within the last 5 minutes, to determine whos online.

I am thinking about including a hidden iframe, including inside it a page to refresh every 30 seconds via javascript, to send a query to update their 'timelastactive' in the database. This would be a better way of guaging whos actually on the site.

This sounds good in theory, but would it actually work? And would all of those extra queries cause a system slowdown?

Posted: Wed Aug 24, 2005 1:34 am
by feyd
personally, I'd do it with an image, if I wanted this functionality. Although any form of subrequest works. The problem will definitely be the server bogging down due to those update queries. From having the same sort of idea previously, the end result was just a pain. We had it set for three minutes between updates, but with 1100 users online at a time, that'd eat the server pretty quickly... and it did. All pages were affected because of the backlog in processing.. not a pretty sight.

Nasty

Posted: Wed Aug 24, 2005 1:46 am
by AnarKy
I once had a webcam in our LAN and FTP'd a picture from a it every 10 seconds.
So that It could appear on our class site. This was when I was in my 1st year of university,

My LAN account was then temporarily suspended because I was using up all the space on the server.
I was overwriting the picture, but the log file was becoming enourmous....
I was adding a line to the log for every FTP transaction.... How was i to know?!

Posted: Wed Aug 24, 2005 10:52 am
by nielsene
Yeah, like feyd said, do it with an image. But if to help reduce the load, I'd do something like

Code: Select all

// in your config file
define('UPDATE_PERCENT',15);  // what percentage of hits to update lastvisited
define('ACTIVE_DELAY',15*60); // When is last active considered on-line

// in your wrapper around the image file

$randomNum = rand(0,100);
if ($randomNum < UPDATE_PERCENT) {
  // update last visit timestamp in DB
}
You'll have to play some "games" with those two constants. If you have a site where people tend to be highly active -- that is they click lots of links, etc. You can have a rather low UPDATE_PERCENT, like 10, and a medium delay like 10 minutes. If the site is less active you'll need to raise one or both, etc