Re: Apache::Session not updating (writing)
[prev]
[thread]
[next]
[Date index for 2005/05/11]
On 5/10/05, Bart Simpson <batttmannn1976@xxxxx.xxx> wrote:
>=20
> --- Rick <rapichai@xxxxx.xxx> wrote:
> > I'm having problems with
> > MasonX::Request::WithApacheSession (using
> > Apache::Session::MySQL backend). The session is not
> > being updated, so
> > I can't save any data to it. I verified this by
> > looking at the mysql
> > logs.
>=20
> Are you timestamping your session each time you
> updated it? it only updates if you change someting in
> top level of session hash, thus usually you timestamp
> the session in top level when updating it.
>=20
> $session->{hash}->{key} =3D $new_val ; # won't cause
> update
>=20
> $session->{hash} =3D { key =3D> $new_val }; # causes
> update cause hash address changed in top level.
>=20
> See docs Apache::Session docs for details about this.
> Other than this I've never had this problem. Don't use
> mason though.
Interesting, it appears that the only API to the
MasonX::Request::WithApacheSession is through the mason request object
(global $m). In order to test what you have recommended, I created a
session using purely the Apache::Session::MySQL class. I did this by
creating a seperate "set.html" mason/html file which creates a new
session and sets some session values. The code is below:
-------------------BEGIN MASON CODE FOR
"set.html"-------------------------------------------------
<%perl>
my %session;
tie %session, 'Apache::Session::MySQL', undef, {
Handle =3D> $DBH,
LockHandle =3D> $DBH
};
</%perl>
<h3>Setting some of the session keys<h3>
<%perl>
$session{'car'} =3D {
make =3D> 'BMW',
year =3D> '2005',
model =3D> 'M3',
color =3D> 'Interlagos Blue'
};
$session{'user'} =3D $USEROBJECT;
</%perl>
<h3>Dumping contents of %session <% $session{_session_id} %></h3>
% for my $key (keys %session) {
<h3><% $key %> =3D <% $session{$key} %></h3>
% }
<h3><a href=3D"dump.html?id=3D<% $session{_session_id} %>">dump.html</a></h=
3>
-------------------END MASON CODE FOR
"set.html"-------------------------------------------------
By viewing this page, the session key/values show up correctly in the
HTML output. However, when I click the link to go to the dump.html
page, nothing was saved. Below is the output for the dump.html page.
-------------------BEGIN MASON CODE FOR
"dump.html"-------------------------------------------------
<%args>
$id
</%args>
<%perl>
my %session;
tie %session, 'Apache::Session::MySQL', $id, {
Handle =3D> $DBH,
LockHandle =3D> $DBH
};
</%perl>
<h3>DUMPING Session from %session</h3>
% for my $key (sort keys %session) {
<h3><% $key %> =3D <% $session{$key} %></h3>
% }
<h3><a href=3D"set.html">set.html</a></h3>
-------------------END MASON CODE FOR
"dump.html"-------------------------------------------------
On this page, the only key/value pair is: _session_id =3D> [MD5sessionidgoe=
shere]
I checked the MySQL logs and there were only 3 calls to it:
2005 Query SELECT
GET_LOCK('Apache-Session-f050450049018ff9d77c9e4697700b5f', 3600)
2005 Query INSERT INTO sessions (id, a_session) VALUES
('f050450049018ff9d77c9e4697700b5f','\0\0\0\n
f050450049018ff9d77c9e4697700b5f\0\0\0
_session_id')
2005 Query SELECT
RELEASE_LOCK('Apache-Session-f050450049018ff9d77c9e4697700b5f')
No UPDATE statements even though I'm changing things in the top level hash.
Any ideas?
Rick