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

Update: The problem is with the Scalar::Util version. Having an upto date version in the path didn't help.

Using CGI::Session with file storage has been fine.

On my local m/c I got an app working using MySQL as storage. I uploaded this to the webhoster and I got errors about missing CGI::S drivers (dbi, mysql). I 'installed' (copied) these from my m/c and then got an error about refaddr in Scalar::Util. I installed that too. No more errors but the sessions weren't being saved. :-(

Worse, now the previous app (file storage) behaved/failed the same way. Deleting the modules I'd copied over restored it to normal service.

I have production apps happily using MySQL and I'm also using modules I've copied to a local/private lib (e.g. CGI::Simple and HTML::Template). This leads me to believe it might be some version clash in the dependancy train.

I'm on WinXP and the webhoster is solaris. Could it be a platform issue?

How would monks go about tracking down a problem like this?

  • Comment on CGI::Session/MySQL dependancy/version woes

Replies are listed 'Best First'.
Re: CGI::Session/MySQL dependancy/version woes
by jdtoronto (Prior) on Sep 16, 2006 at 16:38 UTC
    wfsp,

    I'm on WinXP and the webhoster is solaris. Could it be a platform issue?

    I have used (and still do in some legacy code) this module on WinXP (development), CentOS4 (current production) and Red Hat 7.3 (legacy production) and have never had an issue. To go a little further, I have never seen any dependency issues with this package.

    Maybe if you could write us a little test case, I at least, would be happy to put it up on one of my servers and see what happens.

    jdtoronto

      jdtoronto

      Thanks for your response.

      #!/usr/bin/perl #!c:\Perl\bin\perl.exe use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use lib qw(/path/to/lib_dev); use CGI::Simple; use CGI::Session; # v4.13 (was v3.11) use HTML::Template; use DBI; # v1.32 my $q = CGI::Simple->new() or die "can't create query object: $!"; my $dbh = DBI->connect('DBI:mysql:database=mydb;host=myhost', 'myuid', + 'mypwd') or die "can't connect to db"; my $sid = $q->cookie("CGISESSID") or undef; my $s = CGI::Session->new(undef, $sid, {Handle => $dbh}) or die CGI::Session->errstr; # corrected $_ = $q->param('a'); if (/next/) { next_page() } elsif (/prev/) { previous_page() } else { first_page() } sub next_page { my $first = $s->param('f'); $first += 20; $s->param('f', $first); print_output($first); } sub previous_page { my $first = $s->param('f'); $first -= 20; $s->param('f' => $first); print_output($first); } sub first_page{ $s->param('f', 0); print_output(0); } sub print_output { my ($first) = @_; my $file = 'tmpl/session.html'; my $t = HTML::Template->new( filename => $file ) or die "can't find $file: $!"; $t->param({first => $first}); print $s->header; print $t->output; }
      tmpl/session.html
      <html> <head> <title>sessions</title> </head> <body> <a href="/z/session.cgi?a=prev">previous</a> <a href="/z/session.cgi?a=next">next</a> <p><TMPL_VAR NAME=first></p> </body> </html>
      Response Headers - http://www.somedomain.org.uk/z/session.cgi?a=next Server: Zeus/4.2 Date: Sun, 17 Sep 2006 06:46:36 GMT Set-Cookie: CGISESSID=a26c68329dbf87f6e5d69ff416ab1314; path=/ Content-Type: text/html; charset=ISO-8859-1 Transfer-Encoding: chunked 200 OK
      Update

      Adding:

      die Dumper $s;
      to the next_page sub produces:
      Software error: $VAR1 = bless( { '_API_3' => { 'ID' => 'MD5', 'SERIALIZER' => 'Default', 'DRIVER' => 'File' }, '_STATUS' => 1, '_file_path' => '/cgisess_d71ef41aa899089fdf39190ea38 +0d10e', '_DATA' => { '_SESSION_ETIME' => undef, '_SESSION_ID' => '86c76f868575c30ccd29e3 +ebb7ca3c03', '_SESSION_ATIME' => 1158477726, '_SESSION_EXPIRE_LIST' => {}, '_SESSION_REMOTE_ADDR' => '86.139.50.197 +', '_SESSION_CTIME' => 1158477726 }, '_OPTIONS' => [ 'd71ef41aa899089fdf39190ea380d10e', { 'Handle' => bless( {}, 'DBI::db' ) } ] }, 'CGI::Session::File' );
      Update 2

      After uploading Session.pm (see comment re version) and the Session dir:

      Software error: $VAR1 = bless( { '_STATUS' => 1, '_OBJECTS' => { 'id' => 'CGI::Session::ID::md5', 'driver' => bless( { 'Directory' => ' +/tmp', 'NoFlock' => 0, 'UMask' => 432, 'Handle' => bles +s( {}, 'DBI::db' ) }, 'CGI::Session:: +Driver::file' ) }, '_CLAIMED_ID' => 'd71ef41aa899089fdf39190ea380d10e', '_DATA' => { '_SESSION_ID' => 'cf417d8baa05dfe64bcc53 +088b736740', '_SESSION_ATIME' => 1158478795, '_SESSION_REMOTE_ADDR' => '86.139.50.197 +', '_SESSION_CTIME' => 1158478795 }, '_QUERY' => undef, '_DRIVER_ARGS' => $VAR1->{'_OBJECTS'}{'driver'}, '_DSN' => { 'serializer' => 'default', 'id' => 'md5', 'driver' => 'file' } }, 'CGI::Session' );
      After removing the die statement
      Undefined subroutine &Scalar::Util::refaddr called at /xxx/lib_dev/CGI +/Session/Serialize/default.pm line 53.
      Scalar::Util is there (v1.18) and it contains sub refaddr.