LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 04-11-2011, 08:49 AM   #1
merlininthewood
LQ Newbie
 
Registered: Oct 2004
Location: Devon, England
Distribution: Ubuntu 10.04, Debian Lenny
Posts: 21

Rep: Reputation: 0
Question Perl Apache Session MySQL inconsistency on Debian Lenny


Hi

I have been tearing my hair out with this. As part of a backend perl script i am holding the Epoch time as session data using apache session and mysql so i can delete sessions after an expiry period. When I retrieve the time it is about three months old even when i only just set it. The code example below best describes the problem:

I have got the table set up that Apache session requires.
Code:
#!/usr/bin/perl

use strict;
use DBI;
use Apache::Session::MySQL;

my %config;

  $config{'dbname'} = "somedatabase";				# Database name
  $config{'dbuser'} = "root";			# Database user
  $config{'dbpass'} = "secret";				# Database password
  
my $dbhg = DBI->connect("dbi:mysql:$config{'dbname'}",$config{"dbuser"},$config{"dbpass"})
	or die "Could not open MySQL DataBase - SQL Error: $DBI::errstr\n";
	
my %session;

tie %session, 'Apache::Session::MySQL', undef, {Handle=>$dbhg, LockHandle=>$dbhg};

my $sessid = $session{_session_id};

print "New session:$sessid\n";
	 
$session{'time'} = time;

print "Time set: $session{'time'}\n";

untie %session;

#### Now to retie the session and retrieve the time

tie %session, 'Apache::Session::MySQL', $sessid, {Handle=>$dbhg, LockHandle=>$dbhg};

print "Connected session:$session{_session_id}\n";

my $retrievedTime = $session{'time'};
	 
print "Retrieved time: $retrievedTime\n";

untie %session;
This gives the output:

Code:
New session:14199f84b1e646b528d63b3be180a9b1
Time set: 1302529444
Connected session:14199f84b1e646b528d63b3be180a9b1
Retrieved time: 1295975743
This is happening on 3 out of four machines all running Debian. It works fine on the one!?!?!

Anyone got any ideas?
 
Old 04-11-2011, 11:35 PM   #2
mgichoga
Member
 
Registered: Sep 2004
Distribution: Ubuntu
Posts: 42

Rep: Reputation: 16
Ran the same code and works for me. I'm running ubuntu 10.10 You could try add a 'undef %session' right after the first 'untie %session' so that it looks like this:

Quote:
untie %session
undef %session
I don't know if this will lead to other problems with the key=>values pairings but might be a troubleshooting tool.

Also are you running the MySQL database and the perl script on the same machine? Have you checked time on local machine...probably so.

Michael

Last edited by mgichoga; 04-11-2011 at 11:42 PM.
 
Old 04-12-2011, 04:44 AM   #3
merlininthewood
LQ Newbie
 
Registered: Oct 2004
Location: Devon, England
Distribution: Ubuntu 10.04, Debian Lenny
Posts: 21

Original Poster
Rep: Reputation: 0
Thanks for your reply. I tried using undef %session but with the same result. The actual script i am using this in is a mod perl script that is called on separate occasions between setting and retrieving the session data (hence the need to use apache session!!). I wrote the script above to see if it was a problem with my main script or mod perl but the phenomenon occurs on this simple perl script also. It always returns a time some time in the afternoon (but different times) on Tuesday the 25th January 2011. How weird is that?

Two of the machines it occurs on (and the one where it works OK) are running Apache::Session 1.86 and the other 1.87 (upgraded to Squeeze). The database is run on the same machine as the script in all cases.

I have googled but found no-one who has come across a similar problem.
 
Old 04-13-2011, 02:52 PM   #4
merlininthewood
LQ Newbie
 
Registered: Oct 2004
Location: Devon, England
Distribution: Ubuntu 10.04, Debian Lenny
Posts: 21

Original Poster
Rep: Reputation: 0
It gets even more weird. I started poking around inside Session.pm to see where the inconsistency starts. I added some print commands to give me an idea what the values are as they are processed by apache session and it started working as it should. I narrowed it down to adding a print command in the STORE routine:
Code:
sub STORE {
    my $self  = shift;
    my $key   = shift;
    my $value = shift;
    print "VALUE=$value\n"; #####################
    $self->{data}->{$key} = $value;
    
    $self->{status} |= MODIFIED;
    
    return $self->{data}->{$key};
}
Now my script returns:
Code:
New session:fa8aa2bc8531313007e0463920fbd25d
VALUE=1302723468
Time set: 1302723468
Connected session:fa8aa2bc8531313007e0463920fbd25d
Retreived time: 1302723468
As it should. And when i remove the print statement again:
Code:
New session:92344b19524a01f524bd6afe56bbdec0
Time set: 1302723485
Connected session:92344b19524a01f524bd6afe56bbdec0
Retreived time: 1295990591
Can anyone think why printing the $value string would make it behave differently? I tried setting 'my $tmp=$value;' as an ugly fix but that didn't work.
 
Old 04-13-2011, 11:45 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
If you're really sure you've found a bug in Session.pm, you can notify the maintainer; look up the module at search.cpan.org http://search.cpan.org/~rsoliv/Session-0.01/Session.pm.
Also, you may want to raise this at perlmonks.org; where all the Perl gurus hang out.
 
Old 04-14-2011, 07:47 AM   #6
merlininthewood
LQ Newbie
 
Registered: Oct 2004
Location: Devon, England
Distribution: Ubuntu 10.04, Debian Lenny
Posts: 21

Original Poster
Rep: Reputation: 0
I have raised this on perlmonks.org if anyone wants to follow it there.
 
  


Reply

Tags
apache, debian, mysql, perl, session


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] After Debian upgrade from Lenny to Squeeze, MySQL will not start fireball1974 Linux - Server 3 03-20-2011 07:28 PM
Couldn't start mysql services on Debian Lenny Tueleep86 Linux - Newbie 6 10-12-2010 02:25 AM
LXer: Apache And MySQL Monitoring With Bijk On Debian Lenny LXer Syndicated Linux News 0 06-28-2010 05:30 PM
Perl: Storing Cart-Like items in Mysql without CGI::Session zachet Programming 5 03-11-2010 11:29 AM
Segmentation fault (11) with Debian Lenny and Apache dEM0nsTAr Linux - Server 1 11-15-2009 08:22 AM


All times are GMT -5. The time now is 07:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration