[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: mod_perl best practices cleanup
From:       Robert Landrum <rlandrum () aol ! net>
Date:       2007-01-22 15:41:15
Message-ID: 45B4DB1B.9060608 () aol ! net
[Download RAW message or body]

Tracy12 wrote:
> I tried to declare 
> use vars qw( $SESSION_CLEANUP_COUNTER); and increment within the code doent
> seem to work,
> 
> Shoud i increment this in a specific hanlder.
> 

You really need to heed the advice of the list and consider using the a 
cron job to expire old sessions.  It's really not that hard to do.

#!/usr/bin/perl

use strict;
my $path = shift;  # path to session directory
my $exp = shift;   # time sessions are valid (in seconds)
my $now = time;
opendir(DIR,$path) or die "could not open dir: $path: $!";
while(my $file = readdir(DIR)) {
   my $fp = "$path/$file";
   my $mtime = (stat($fp))[9];
   if($now > ($mtime + $exp)) {
     unlink($fp);  # remove the file if expired
   }
}
closedir(DIR);

__END__

I didn't test this, so it probably doesn't work as written.  But it 
should be close enough to give you the idea.  All it does is delete 
files when they have been sitting around for more than a certain number 
of seconds.

Add that to cron as something like

* * * * * /path/to/session_remover.pl /path/to/session/dir 3600

That'll check for newly expired sessions every minute and delete any 
that are older than 3600 seconds (1 hour).

Good luck,

Rob
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic