private function obtain_guest_count_24() { $total_guests_online_24 = 0; // Get number of online guests for the past 24 hours // caching and main sql if none yet if (($total_guests_online_24 = $this->cache->get('_total_guests_online_24')) === false) { // teh time $interval = time() - 86400; if ($this->db->get_sql_layer() === 'sqlite' || $this->db->get_sql_layer() === 'sqlite3') { $sql = 'SELECT COUNT(session_ip) as num_guests_24 FROM ( SELECT DISTINCT session_ip FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($interval - (int) ($interval % 60)) . ')'; } else { $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests_24 FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($interval - (int) ($interval % 60)); } $result = $this->db->sql_query($sql); $total_guests_online_24 = (int) $this->db->sql_fetchfield('num_guests_24'); $this->db->sql_freeresult($result); // cache this stuff for, ohhhh, how about 5 minutes // change 300 to whatever number to reduce or increase the cache time $this->cache->put('_total_guests_online_24', $total_guests_online_24, 300); } return $total_guests_online_24; }
private function obtain_guest_count_24() { $total_guests_online_24 = 0; if ($this->config['load_online_guests']) { // Get number of online guests for the past 24 hours // caching and main sql if none yet if (($total_guests_online_24 = $this->cache->get('_total_guests_online_24')) === false) { if ($this->db->get_sql_layer() === 'sqlite' || $this->db->get_sql_layer() === 'sqlite3') { $sql = 'SELECT COUNT(session_ip) as num_guests_24 FROM ( SELECT DISTINCT session_ip FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($this->interval - (int) ($this->interval % 60)) . ')'; } else { $sql = 'SELECT COUNT(DISTINCT session_ip) as num_guests_24 FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . ANONYMOUS . ' AND session_time >= ' . ($this->interval - (int) ($this->interval % 60)); } $result = $this->db->sql_query($sql); $total_guests_online_24 = (int) $this->db->sql_fetchfield('num_guests_24'); $this->db->sql_freeresult($result); // cache this data for 5 minutes, this improves performance $this->cache->put('_total_guests_online_24', $total_guests_online_24, 300); } } return $total_guests_online_24; }