You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Barksdale, Ray" <ba...@mdot.state.ms.us> on 2005/10/05 21:02:20 UTC

RE: What am I missing?

 set a timestamp in your sessions before untying.

> -----Original Message-----
> From: Octavian Rasnita [mailto:orasnita@fcc.ro] 
> Sent: Wednesday, October 05, 2005 2:51 PM
> To: modperl@perl.apache.org
> Subject: What am I missing?
> 
> Hi,
> 
> I am trying to use Apache::Session with mod_perl because I 
> heard that it is a little faster than CGI::Session. The 
> problem is that I cannot save variables in the created 
> sessions. They are created, but no data is saved.
> 
> Here is what I have tried and I am sure I am missing something:
> 
> #Create session:
> my %session;
> eval {
> tie(%session, 'Apache::Session::MySQL', undef, {Handle => 
> $dbh, LockHandle => $dbh}); };
> 
> #Put a variable in it:
> $session{username} = 'etc';
> 
> #get the session id:
> my $session_id = $session{_session_id};
> 
> undef %session;
> 
> #Get the saved session:
> my %new_session;
> eval {
> tie(%new_session, 'Apache::Session::MySQL', $session_id, 
> {Handle => $dbh, LockHandle => $dbh}); };
> 
> #Get the var from the session:
> print $new_session{username};
> 
> undef %new_session;
> 
> ###
> 
> After running this script, nothing is printed and the hash 
> element "username" is not saved in the MySQL table, but just 
> the session ID.
> 
> I have created the MySQL table using:
> 
> create table sessions(id varchar(32) not null primary key, 
> a_session text);
> 
> Thank you.
> 
> Teddy
> 
> 
> 

Re: What am I missing?

Posted by Perrin Harkins <pe...@elem.com>.
Barksdale, Ray wrote:
>  set a timestamp in your sessions before untying.

That's for telling it that the session has changed by doing a first 
level write to the tied hash.  This is only necessary when you are 
writing to the second level and not touching the first, e.g.

$session->{'user'}->{'favorite_color'} = 'mauve';

It doesn't need to be a timestamp either.  Just doing this every time 
will work fine:

$session->{'touch'} = 1;

In any case, that doesn't seem to be the problem here.

- Perrin

Re: What am I missing?

Posted by Malcolm J Harwood <mj...@liminalflux.net>.
On Thursday 06 October 2005 09:46 am, Octavian Rasnita wrote:

> It is very strange indeed, because if I use:
>
> eval{untie %session;}; print STDERR $@ if $@;
>
> instead of:
>
> untie %session;
>
> ... the program works fine, with no error on the screen and *no error in
> the log file*.

sub handler
{
....

untie %session; #This line creates problems.

#end handler
}


Aren't you supposed to be returning Apache2::Const::OK from the handler?

My guess is that "untie %session" returns something (probably undef) that 
triggers a failure, whereas your print-if test returns something that equates 
to OK.



-- 
"Why don't you try practicing random acts of intelligence
 and senseless acts of elf-control?"

Re: What am I missing?

Posted by Octavian Rasnita <or...@fcc.ro>.
From: "Tom Schindl" <to...@gmx.at>

> > If I comment out "untie %session;, the program doesn't give errors, but
if I
> > let that line in the program, it gives an error in the browser "The
server
> > encountered an internal error or misconfiguration and was unable to
complete
> > your request.", however, I cannot find any error in the error log and I
> > don't know what could be the problem.
>
> Strange.
>


It is very strange indeed, because if I use:

eval{untie %session;}; print STDERR $@ if $@;

instead of:

untie %session;

... the program works fine, with no error on the screen and *no error in the
log file*.

I have only 3 error log files and I have checked them all, but I couldn't
find any error.

When I was using only "untie %session", the program use to print an error on
the browser, but that error was below the result of the program, so the
program was working, but there was that error added (A heading with "OK" in
it).

Thank you. I still don't know what's the problem, but it works fine now.

Teddy



Re: What am I missing?

Posted by Tom Schindl <to...@gmx.at>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Octavian Rasnita wrote:
> Regarding the same Apache::Session issue....
> 
> I have created a program which has the form below.
> If I comment out "untie %session;, the program doesn't give errors, but if I
> let that line in the program, it gives an error in the browser "The server
> encountered an internal error or misconfiguration and was unable to complete
> your request.", however, I cannot find any error in the error log and I
> don't know what could be the problem.

Strange.

[...]

> my $j = Apache2::Cookie::Jar->new($r);
> my $session_id = $j->cookies('SESSION_ID');
> $session_id =~ s/^SESSION_ID=// if $session_id;
> 
> my $dbh = General::MySQL::dbh(database => 'house');
> 
> my %session = ();
> eval {
> tie(%session, 'Apache::Session::MySQL', $session_id, {Handle => $dbh,
> LockHandle => $dbh});
> };

You do an eval but you don't catch if there's an error by testing $@.

[...]

Try adding "print STDERR" to find at which line your program stops
execution.

Maybe you should also eval{ } the untie'ing of the session?

Tom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
Comment: Using GnuPG with Mandriva - http://enigmail.mozdev.org

iD8DBQFDRPpQkVPeOFLgZFIRAhSbAKCIUFtMmOysPGIIYRPKwBvEXq5PgACgj9qj
GID9bsCZuX0OLNacZOh5Rio=
=mVRr
-----END PGP SIGNATURE-----

Re: What am I missing?

Posted by Aaron Ross <aa...@aaronelliotross.com>.
> your request.", however, I cannot find any error in the error log and I
> don't know what could be the problem.

You need to figure out where the error message is going. If you are 
getting an internal server error, there is surely an error message in 
the error log.

Are you sure you are looking at the right error log? Try putting a die 
statement in your script to verify you can find the error in the logs.

It's going to be very hard to help you if you can't find the error 
messages produced by your script.

> my %session = ();
> eval {
> tie(%session, 'Apache::Session::MySQL', $session_id, {Handle => $dbh,
> LockHandle => $dbh});
> };

I believe someone already mentioned it, but you should be checking the 
value of $@ after this eval.

if ($@) { ... something went wrong ... }

Aaron

Re: What am I missing?

Posted by Octavian Rasnita <or...@fcc.ro>.
Regarding the same Apache::Session issue....

I have created a program which has the form below.
If I comment out "untie %session;, the program doesn't give errors, but if I
let that line in the program, it gives an error in the browser "The server
encountered an internal error or misconfiguration and was unable to complete
your request.", however, I cannot find any error in the error log and I
don't know what could be the problem.

Can you tell me if the program has a good written form or what else might
cause that error?

Thank you.

package House::Portfolio;

use strict;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();
use Apache2::Request ();
use Apache2::Cookie ();
use Apache2::Const -compile => qw(:common);
use Apache::Session::MySQL ();

use General::MySQL ();
use Digest::MD5 qw(md5_hex);

sub handler {
my $r = shift;

my $j = Apache2::Cookie::Jar->new($r);
my $session_id = $j->cookies('SESSION_ID');
$session_id =~ s/^SESSION_ID=// if $session_id;

my $dbh = General::MySQL::dbh(database => 'house');

my %session = ();
eval {
tie(%session, 'Apache::Session::MySQL', $session_id, {Handle => $dbh,
LockHandle => $dbh});
};

#Get the real session id:
$session_id = $session{_session_id};

my $cookie = Apache2::Cookie->new($r, -name => 'SESSION_ID', -value =>
$session_id, -path => '/', -domain => $r->hostname);
$cookie->bake($r);

my $q = Apache2::Request->new($r);
my $action = $q->param('a');

unless($session{username}) {
if ($action and $action eq 'login') {
&login($r, $q, $dbh, \%session);
}
else {
&login_form($r, $q, $dbh, \%session);
}
}
else {
#The user is logged in
#Here are called more subroutines based on some conditions...
#Some of these subroutines might add something to the session by $session
which is a reference to %session ($session->{var} = "...")
}

untie %session; #This line creates problems.

#end handler
}

#Here are defined the other subroutines which are called in the handler.

1;


Teddy

----- Original Message ----- 
From: "Jeff" <mo...@aquabolt.com>
Cc: <mo...@perl.apache.org>
Sent: Thursday, October 06, 2005 10:39 AM
Subject: Re: What am I missing?


> Wow! I like that - an answer, about timestamps, posted 50 minutes before
> the question arrived! Is it just a temporal anomaly? or some form of
> mod_perlish quantum tunnelling? Ain't this list fab. ;)
>
>
> -------- Original Message --------
> From: "Barksdale, Ray" <ba...@mdot.state.ms.us>
> To: "Octavian Rasnita" <or...@fcc.ro>
> CC: modperl@perl.apache.org
> Subject: Re:What am I missing?
> Date: 5/10/2005 20:02
>
> >  set a timestamp in your sessions before untying.
> >
> >
> >>-----Original Message-----
> >>From: Octavian Rasnita [mailto:orasnita@fcc.ro]
> >>Sent: Wednesday, October 05, 2005 2:51 PM
> >>To: modperl@perl.apache.org
> >>Subject: What am I missing?
> >>
> >>Hi,
>


Re: What am I missing?

Posted by Jeff <mo...@aquabolt.com>.
Wow! I like that - an answer, about timestamps, posted 50 minutes before 
the question arrived! Is it just a temporal anomaly? or some form of 
mod_perlish quantum tunnelling? Ain't this list fab. ;)


-------- Original Message --------
From: "Barksdale, Ray" <ba...@mdot.state.ms.us>
To: "Octavian Rasnita" <or...@fcc.ro>
CC: modperl@perl.apache.org
Subject: Re:What am I missing?
Date: 5/10/2005 20:02

>  set a timestamp in your sessions before untying.
> 
> 
>>-----Original Message-----
>>From: Octavian Rasnita [mailto:orasnita@fcc.ro] 
>>Sent: Wednesday, October 05, 2005 2:51 PM
>>To: modperl@perl.apache.org
>>Subject: What am I missing?
>>
>>Hi,