1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
use strict ;
use Safe ;
...
# get list of session files
my $FilesList = [glob($Instance->{sesstmpdir}.'*')] ;
my $CleanupList = [] ;
# sandbox for safe eval
my $Safe = new Safe() ;
foreach my $FileName (@{$FilesList})
{
open FILE, $FileName ;
my $Data = undef ;
while (<FILE>)
{
$Data .= $_ ;
}
# remove possible '\n'
my ($SafeString) = $Data =~ m/^(.*)$/ ;
# deserialize session file content
my $Session = $Safe->reval($SafeString) ;
# check if session if expired
if ($Session->{_SESSION_ETIME} and $Session->{_SESSION_CTIME} + $Session->{_SESSION_ETIME} < time)
{
push @{$CleanupList}, $FileName ;
}
close FILE ;
}
# remove all expired session files
foreach my $FileName (@{$CleanupList})
{
unlink $FileName ;
} |
Partager