in reply to Re^3: Printing files age information help!
in thread Printing files age information help!

Hi, I've tried deleting the sessions with something like this, and no success:
#!/usr/bin/perl -w use strict; use CGI qw(-oldstyle_urls :standard); use CGI::Carp qw(fatalsToBrowser); use File::Find; use File::stat; use Time::localtime; my $mytime=(time); my $file_stat; my $dir_session = "../sessions"; print header(); opendir(DIR, $dir_session) or die "Couldn't open directory, $!"; while (my $sessions = readdir DIR) { if($sessions=~ /^cgisess_[a-f0-9]{32}$/) { CGI::Session->find( \&purge ); } } closedir DIR; sub purge { my ($session) = @_; next if $session->is_empty; # <-- already expired?! if ( ($session->ctime + 60*55) <= time() ) { $session->delete(); $session->flush(); # Recommended practice says use flush() + after delete(). } }

Any suggestions? Thanks!

Replies are listed 'Best First'.
Re^5: Printing files age information help!
by Anonymous Monk on Jan 16, 2011 at 21:49 UTC
    Any suggestions? Thanks!

    Get rid of all opendir/readdir... its just clutter

    If you want CGI::Session to look for sessions $dir_session, you have to call ->find with the appropriate arguments

      OK, could you provide any kind of code that would kind of work? I've tried, if you have more experience with this, would be nice to see some sample code, thanks!