Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

State-keeping modules

by jpfarmer (Pilgrim)
on Mar 02, 2005 at 17:19 UTC ( [id://435930]=perlquestion: print w/replies, xml ) Need Help??

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

I've been researching modules for maintaining session state and reading the comments on CPAN, there doesn't appear to be a clear favorite. Both CGI::Session and Apache::Session seem to be on the right track, but Apache::Session's CPAN rating is mixed and CGI::Session doesn't have many comments, so I'm not sure that the rating has enough input to be useful.

Is there a better module to use, should I use one of these, or should I just roll my own?

Replies are listed 'Best First'.
Re: State-keeping modules
by Tanktalus (Canon) on Mar 02, 2005 at 18:52 UTC

    I would not recommend rolling your own until you've at least tried the existing modules and figured out how they failed to meet your requirements. There are trials and tribulations that have been ensconced within those modules - and rolling your own will merely mean rediscovering those issues. Since they will very likely both be acceptable to your requirements (not that those requirements are entirely clear - winning a popularity contest should not be the sum total of your requirements), pick the one that has the API that you find easier.

    (For the record, I use CGI::Session, and have also written a back-end driver for it for use with the database that I use.)

Re: State-keeping modules
by TedYoung (Deacon) on Mar 02, 2005 at 18:27 UTC

    I have been using CGI::Session for several years, through dozens of projects and am very happy with it. It is quite flexible, and when used with storable is quite fast. However, I have never used Apache::Session and cannot compare the two.

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
Re: State-keeping modules
by saberworks (Curate) on Mar 02, 2005 at 19:13 UTC
    We have been using Apache::Session for a few months now and for some reason we are running into a fairly persistent problem: the session->DESTROY method isn't being called automatically all the time (only sometimes) so any time we start running into session issues, we have to throw a tied(%$sess)->DESTROY(); call. The symptoms: variables seem to randomly fail to get recorded to the session or deleted from the session when the script is finished running. The other programmer I work with thinks it's our convoluted scripts confusing perl's garbage collector.

      I, very often, have the same problem with CGI::Session (which will flush on DESTROY if you haven't done it explicitly). In my case too it is likely something I have done else where. I just have found it easier to explicitly flush the session at the end of the request, than to debug what I am doing.

      Ted Young

      ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
      To amplify on TedYoung's reply, this mentions doing the flush manually, just to be sure.
Re: State-keeping modules
by jdtoronto (Prior) on Mar 02, 2005 at 19:26 UTC
Re: State-keeping modules
by perrin (Chancellor) on Mar 03, 2005 at 00:05 UTC
    You might want to look at Apache::SessionManager if you're using mod_perl. It handles a lot of the details for you. The persistence is done with Apache::Session.
      UPDATE Rewritten due to negative reputation directed at my previously short post (possibly taken as abrupt...)

      Thanks perrin.
      I'm not using mod_perl at this stage. Are there any other solutions than appending the session id to the query string?

        Not really. Both modules have problems, but both are now actively maintained.
Re: State-keeping modules
by borisz (Canon) on Mar 02, 2005 at 19:16 UTC
Re: State-keeping modules
by snookmz (Beadle) on Mar 02, 2005 at 19:57 UTC
    I have not used CGI::Session or Apache::Session, but I have written a fairly simple module for maintaining state without cookies.

    What I do is create a unique ID string, parse the html before it's outputted and tack it on to the end of any link. All ID's are tracked from a Mysql database, but they needn't be and could be kept in temp files.

    That is a simplified explanation of what my module actually does, but as the implementation of stateful sessions over http seemed fairly straight forward I didn't even think to see if there was a module pre-written for it.
      Sure, that's not a bad idea, but what happens when someone book marks the link? What about somebody copying the url and passing it to a friend? What about storing the link in an online bookmark type site? What about pasting it to a forum or something to share it?
        I use CGI::Session to maintain state in my applications. I also tack the CGISESSID value onto the end of each url in case a user does not have cookies enabled.

        I understand your comment on bookmarking and linking problems with session-id-appended urls, but am not sure if there are any other ways to deal with browsers with cookies turned off, or user agents with no cookie capability. Any suggestions? (I'm open to other options from what I am using at the moment for those reasons outlined)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://435930]
Approved by Joost
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found