in reply to Suggestions on cleaning up session files

I'm thinking of using cron and reading the files' dates

That's exactly what I do. Works like a charm.

Sample code:

my $tmp_path = "/tmp/myapp"; my $max_age = 60*60*24; # e.g. one day my $t_keep = time() - $max_age; my @stale_sessfiles = grep { (stat $_)[9] < $t_keep } # files older than $t_keep glob "$tmp_path/cgisess_*"; # print STDERR "$_\n" for @stale_sessfiles; # debug unlink @stale_sessfiles;

Replies are listed 'Best First'.
Re^2: Suggestions on cleaning up session files
by Anonymous Monk on Mar 20, 2009 at 15:04 UTC
    Thanks for your code :) You wrote "Sample code". Does it work as it? Do I have to make changes to it?

      Well, you might need to adjust $tmp_path and $max_age, and then configure things to have it run via cron.  You wouldn't risk much just giving it a try :) — there really isn't much to it, after all... And in case you're paranoid, you can always first comment out the unlink line, and uncomment the debug print to check what would be deleted...