http://www.perlmonks.org?node_id=111884

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

Hello,

A search for 'session' and 'sessions' on this site has, suprisingly, revealed nothing.

I am trying to find the 'best' way to handle user sessions on the websites I have written in Perl. The current methods involve storing a session ID (20 characters, or something like that) in a database/file and retrieving at the start of every page.

This does not seem efficient.

Are there any better ways to do this? Can I store sessions in memory?

I am not using mod_perl if that matters.

Cheers,

fx Edited by boo_radley : closed <b> tag

  • Comment on Writing web pages in Perl with sessions

Replies are listed 'Best First'.
Re: Writing web pages in Perl with sessions
by broquaint (Abbot) on Sep 12, 2001 at 16:37 UTC
    I'm no web perl guru, but I've heard on the grapevine that the Apache::Session module could be just you're ticket. It should work even if your not running Apache or mod_perl.
    HTH

    broquaint

      I, too, must advocate the use of Apache::Session. According to a history of the module I read, it has little to do with Apache or Sessions itself and is called "Apache::Session" purely for historical reasons.

      Apache::Session is the underlying framework to implement your own session system. It's basically an interface to an object store. You tie a hash to, lets say Apache::Session::DBI, use your hash as you like, then when you come back with an id of some sort (from a cookie perhaps, or a session url like http://example.com/session/3F48dfj12578w), your hash will be restored.

      The nice thing is that storage methods for files and numerous databases are available. Check out the perldoc on it for some examples. As one who rolled his own session management system before discovering this, I highly recommend using this before reinventing another wheel. =)

      -Ducky

        So, Apache::Session is perhaps the way to go - I shall look at that.

        However, I am still wondering, is there a way to use memory? Surely this would provide quicker storage/access? I seem to remember a particular web-based e-mail client (IMP perhaps?...) using shared memory as a session store...

        fx

Re: Writing web pages in Perl with sessions
by arashi (Priest) on Sep 12, 2001 at 17:37 UTC
Re: Writing web pages in Perl with sessions
by blakem (Monsignor) on Sep 12, 2001 at 16:07 UTC
    Retry your query at Super Search. The regular search is currently a bit buggy....

    -Blake