sesscount does count sessions that are still active by checking if the UPDATED timestamp for an sid (session id) is bigger than the submitted timestamp. So, if we want to see how many sessions are still ongoing for the last x mintues we can do so easiy, splitting it even by guests and users..
Now, WHAT ABOUT if i only want to see new sessions since last time I have checked? I cannot do so just be seeing if the sid's timestamp is bigger than my "pointer in the past.."
So, i would like to see this sess_count function expanded with this feature "$onlynew":
current version:
function sess_count($timestamp = 0, $anonymous = true) {
$query = $anonymous ? ' AND uid = 0' : ' AND uid > 0';
return db_result(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d'. $query, $timestamp));
}
my version:
function sess_count($timestamp = 0, $anonymous = true, $onlynew = false) {
$query = $anonymous ? ' AND uid = 0' : ' AND uid > 0';
$query2= $onlynew ? '' : ' AND sid NOT IN (select sid from {sessions} where $timestamp < %d)';
return db_result(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d'. $query, $timestamp));
For example, now one can easily, also the beginner, count new guests for a the last our without having to count the active guests AGAIN!
Comments
Comment #1
OSLinux commentedSorry, Typo: we need to also add ". $query2" :)
Comment #2
OSLinux commentedFunction write from session.inc
:: Need to add a field manually called sessionstart that once gets filled with time() and will never be updated!
Thus we can make the codeabove work by changing the subquery into: 'where sid NOT IN (select sid from {sessions} where sessionsstart< %d', timestamp"
Comment #3
OSLinux commentedOk, I see it now too, to make it much easier on the server load :)
Comment #4
sunPlease attach a patch, see http://drupal.org/patch/create
Comment #5
sunComment #6
chx commentedComment #7
panchoNo more API changes in D6. Bumping to D7.
Comment #8
Jaza commentedMoving.
Comment #9
pfrenssenThis function has been removed from D7.