speckled has asked for the wisdom of the Perl Monks concerning the following question:

Hi there gurus! I was wondering if cgi::session updates the session expiration time using the atime() as reference.

I'm using cgi::session in one of the projects I'm working on and I can't get it to update the expiration time while the session is still valid and the user is accessing the page: the atime() is correctly incremented, expire() is set at 900 but ctime() is not changing.

Isn't the session suppose to expire after expire() seconds of NO access to the program?

Any idea how to increment the ctime or make the session expire when the page is not accessed and not before?

Thanks in advance and excuse my french
  • Comment on CGI::Session session expiration problems

Replies are listed 'Best First'.
Re: CGI::Session session expiration problems
by Corion (Patriarch) on Jan 16, 2009 at 08:09 UTC

    From looking at the documentation, I see:

    • atime() - Read-only method. Returns the last access time of the session in seconds from epoch. This time is used internally while auto-expiring sessions and/or session parameters.
    • ctime() - Read-only method. Returns the time when the session was first created in seconds from epoch.
    • expire() - Sets expiration interval relative to atime().

    So, expire() seems to look at atime(), at least when in "auto-expire" mode. I don't know what that is, but seeing that you've hidden your relevant code quite well, I guess that you're not using "auto-expire" mode or that your description of what you see does not correlate with what happens.

    Why would you expect ctime() ever to change for one session?

      $s = new CGI::Session("driver:file", undef, {Directory=>'/tmp'}); $s->expire('+15m');


      What I want is to expire the session if no activity. What I get is: session expires after 15m even if there is activity.

      It expires when atime() - ctime() eq expire() even if the user is alive.

      Any clues?

        I don't see anything in the documentation that suggests this behaviour. So, maybe print out the three times and debug from there. The ctime of a file cannot be changed (without erasing and recreating the file), at least on unixish filesystems. But maybe CGI::Session never sees your changing atime.