Traffic has grown a lot and I'm looking to rebuild the users online part.
This is what I currently have
function showusersonline($hidden = false) {
mysql_query("INSERT INTO usersonline(timestamp, ip, location) VALUES ('".time()."', '".$_SERVER['REMOTE_ADDR']."', '".mysql_real_escape_string(LOCATION)."')") or die('Error user 01 '.mysql_error());
mysql_query("DELETE FROM usersonline WHERE timestamp < (".time()." - 900)") or die('Error user 02 '.mysql_error());
$count_users = mysql_num_rows(mysql_query('SELECT DISTINCT ip FROM usersonline')) or die('Error user 03 '.mysql_error());
if($hidden) return '';
return $count_users . ' User'.(($count_users == 1) ? '' : 's').' Online';
}
The whole thing works fine but I'm wondering is their any way of making it more efficient or faster?
I've looked at doing a little mt_rand(1,2) and only delete them on average every second page load reducing it by one query. It might be out by a second or two but I'm not that fussy.
Anyone have any other suggestions on how to make it all more efficient and less of a resource hog?
I know it's basic but that's the level I'm at and why I'm making this topic looking for suggestions from more experienced members.