[ic] Displaying Users Online

Kevin Walsh interchange-users@interchange.redhat.com
Mon Jan 21 09:29:01 2002


Dave Barr wrote:
>
> This is my *very* lax version, doesn't take into account users who
> log out or quit the browser, it only returns how many sessions are
> current (last 60 mins).
>
> [calc]
>    my $sessions = q{[dump-session find=1]};
>    my @array = split(/\s+/, $sessions);
>    my $num = @array;
>    my $out = "Shopping Network Users: " . $num;
>    return $out;
> [/calc]
>
I had a free couple of minutes, so here's a version that lets you
specify the expiration, so you can count sessions that have seen
activity in the last 5 minutes, or whatever inactivity timeout you
choose.

Called like this:

    Sessions with activity: [count-sessions expire="5"]

Gives output like this:

    Sessions with activity: 4


Global usertag follows:

-------------------------------------------------------------------------------
UserTag count_sessions Order expire
UserTag count_sessions Routine <<EOT
sub {
    require File::Find;

    my $expire = shift;

    if ($expire){
        $expire *= 60;
    }
    else{
        $expire = (int($::Variable->{ACTIVE_SESSION_MINUTES}) * 60) or
$Vend::Cfg->{SessionExpire};
    }

    $expire = time() - $expire;
    my @files;

    my $wanted = sub{
        push @files, $_ unless (/\.lock$/ or ! -f $_ or (stat(_))[9] <
$expire);
    };

    File::Find::find($wanted,$Vend::Cfg->{SessionDatabase});
    scalar @files;
}
EOT
-------------------------------------------------------------------------------

That usertag will waste a lot of time, so don't call it on every page :-)

I've not tested the tag properly, but it ought to work.  It's just a
hacked up [dump-session] tag.

--
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.biz
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/