Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Apache::Session::DB_File cleanup issue

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


James.B.Muir at hitchcock

Apr 3, 2012, 12:40 PM

Post #1 of 2 (452 views)
Permalink
Apache::Session::DB_File cleanup issue

Hi All,

I'm using Apache::Session::DB_File to manage some sessions via a mod_perl2 handler and Apache2. I'm running into difficulties trying to read stored data in the sessions db while writing a cleanup cron job to remove old sessions. The following code snippet illustrates the problem:

use strict;
use warnings;
use Fcntl;

use MLDBM qw(DB_File Storable);

use Data::Dumper;

tie my %sessions, "MLDBM", './sessions.db', O_RDWR|O_CREAT, 0666 or die $!;

(tied %sessions)->DumpMeth('portable'); # use Storable::nfreeze

my @keys = map { print "$_\n"; $_; } (keys %sessions);

print Dumper( \%sessions);

untie %sessions;

I am unable to read the stored data when I run the above code. I get the following output -- two session keys (OK) and mysterious error message when I try to dump out a session:

>perl cleanup.pl
e7324413d95fe51f1ac7e74a89b17b47
f72ec1ed349c7140e9f37087e04cd703
Not a SCALAR reference at /usr/local/lib/perl5/site_perl/5.8.8/MLDBM/Serializer/Storable.pm line 28.

I inspected both MLDBM and Apache::Session::DB_File and it looks to me like they both use Storable::thaw to unserialize the data. Any ideas why I am getting this message?

-James



IMPORTANT NOTICE REGARDING THIS ELECTRONIC MESSAGE:

This message is intended for the use of the person to whom it is addressed and may contain information that is privileged, confidential, and protected from disclosure under applicable law. If you are not the intended recipient, your use of this message for any purpose is strictly prohibited. If you have received this communication in error, please delete the message and notify the sender so that we may correct our records.


perrin at elem

Apr 3, 2012, 2:52 PM

Post #2 of 2 (423 views)
Permalink
Re: Apache::Session::DB_File cleanup issue [In reply to]

Hi James,

There are a couple of issues here. One is that
Apache::Session::DB_File doesn't use MLDBM, so you can't use that to
read it. It uses DB_File. The other is that Data::Dumper may not do
what you hope when you hand it a tied variable, i.e. not a real hash.
I'm not certain about that one though.

My advice is to use CGI::Session instead of Apache::Session. It's
less error-prone and is well-maintained.

- Perrin

On Tue, Apr 3, 2012 at 3:40 PM, James B. Muir
<James.B.Muir [at] hitchcock> wrote:
> Hi All,
>
>
>
> Iím using Apache::Session::DB_File to manage some sessions via a mod_perl2
> handler and Apache2. Iím running into difficulties trying to read stored
> data in the sessions db while writing a †cleanup cron job to remove old
> sessions. The following code snippet illustrates the problem:
>
>
>
> use strict;
>
> use warnings;
>
> use Fcntl;
>
>
>
> use MLDBM qw(DB_File Storable);
>
>
>
> use Data::Dumper;
>
>
>
> tie my %sessions, "MLDBM", './sessions.db', O_RDWR|O_CREAT, 0666 or die $!;
>
>
>
> (tied %sessions)->DumpMeth('portable'); # use Storable::nfreeze
>
>
>
> my @keys = map { print "$_\n"; $_; } (keys %sessions);
>
>
>
> print Dumper( \%sessions);
>
>
>
> untie %sessions;
>
>
>
> I am unable to read the stored data when I run the above code. I get the
> following output -- two session keys (OK) and mysterious error message when
> I try to dump out a session:
>
>
>
>>perl cleanup.pl
>
> e7324413d95fe51f1ac7e74a89b17b47
>
> f72ec1ed349c7140e9f37087e04cd703
>
> Not a SCALAR reference at
> /usr/local/lib/perl5/site_perl/5.8.8/MLDBM/Serializer/Storable.pm line 28.
>
>
>
> I inspected both MLDBM and Apache::Session::DB_File and it looks to me like
> they both use Storable::thaw to unserialize the data. Any ideas why I am
> getting this message?
>
>
>
> -James
>
>
>
>
>
>
> IMPORTANT NOTICE REGARDING THIS ELECTRONIC MESSAGE:
>
> This message is intended for the use of the person to whom it is addressed
> and may contain information that is privileged, confidential, and protected
> from disclosure under applicable law. If you are not the intended recipient,
> your use of this message for any purpose is strictly prohibited. If you have
> received this communication in error, please delete the message and notify
> the sender so that we may correct our records.

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.