You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Chris Thompson <ct...@cthompson.com> on 2001/05/22 21:59:52 UTC

Apache::Session not storing changes to hashref

I'm at wits end, I'm hoping someone can tell me what's wrong.

This is Apache 1.3.19, Redhat 6.2, modperl 1.25, apache::session 1.53
and MySQL 3.23.36.

(This is also happening inside HTML::Mason 1.03, but I dont think that has
anything to do with it. I've crossposted to the mason list in case anyone
there has seen this behavior, but what I'm doing isnt really out of the
ordinary, so I dont think it's Mason related)

I've got a hash %s successfully re tied every request. I'm using it to store
a session id and userid with success, so I know it's storing.

Maybe I'm doing too much for A::S but here goes.

I want an entry in the %s hash that is an array of hashrefs

so tied-hash -> array -> hash.

I'm writing this in wizard style, getting one piece of information from the
client per page. The first step is to get a list of domain names, which I do
and store in @domain.

then I do

  my $c=0;
  foreach my $dom (@domain) {
   my $ref = { 'domainname' => $dom,
               'term' => '',
               'ns1name' => '',
               'ns1ip' => '',
               'ns2name' => '',
               'ns2ip' => ''
             };
   $s{regdomains}->[$c++] = $ref;
  }

  this data is all successfully stored in the session.

  We now move to the second page, and if I do a Data::Dumper on %s, I can
actually see the above structure as I envisioned it.

(I'll paraphrase here and not paste the whole dump)

          'regdomains' => [
                            {
                              'ns1name' => '',
                              'ns2ip' => '',
                              'domainname' => 'qwert.com',
                              'term' => '2',
                              'ns2name' => '',
                              'ns1ip' => ''
                            },

Note that 'term'=> '2'.

That's there because before I did the Dumper, I populated the %s with the
data I had on the term. Each term is read from Apache::Request into
@term. (Yes, the orders match)

so I do...

  my $c=0;
  foreach my $term (@term) {
   $s{regdomains}->[$c++]->{term} = $term;
  }

Then I do the Dumper. You can see the result above. Term is set, and I've
verified by changing the term per domain name that the data is going in
correctly.

Now, as I understand it, the tie is causing any data written into the hash
to be written to the database.

The problem is that it's not. When I get to my third page I get four fields
per domain for the nameservers and assign into the hash with...

  my $c=0;
  foreach (@{$s{regdomains}}) {
   $s{regdomains}->[$c]->{ns1name} = $nsn1[$c];
   $s{regdomains}->[$c]->{ns1ip} = $nsip1[$c];
   $s{regdomains}->[$c]->{ns2name} = $nsn2[$c];
   $s{regdomains}->[$c]->{ns2ip} = $nsip2[$c];
   $c++;
  }

I then do a Dumper and get...


          'regdomains' => [
                            {
                              'ns1name' => 'a',
                              'ns2ip' => 'd',
                              'domainname' => 'qwert.com',
                              'term' => '',
                              'ns2name' => 'c',
                              'ns1ip' => 'b'
                            },

you'll see that term is now empty. I've watched the db, and reading it's
cryptic scrawl, I never see any entries for term.

HELP!


-- 
________________________________________________________________________
| Chris Thompson                                      ct@cthompson.com | 
+----------------------------------------------------------------------+

Re: [Mason] Apache::Session not storing changes to hashref

Posted by Dave Baker <da...@dsb3.com>.
On Tue, May 22, 2001 at 03:59:52PM -0400, Chris Thompson wrote:
> I'm at wits end, I'm hoping someone can tell me what's wrong.

[snip]

This is documented (Apache::Session doesn't recurse into the data
structure to look for changes) somewhere ...

I use this whenever changing the session to force it to always get written
back to the database:
  tied(%session)->make_modified;

Dave


-- 

-  Dave Baker  :  dave@dsb3.com  :  dave@devbrain.com  :  http://dsb3.com/
GnuPG: 1024D/D7BCA55D / 09CD D148 57DE 711E 6708  B772 0DD4 51D5 D7BC A55D


[Mason] Apache::Session not storing changes to hashref

Posted by Jared Rhine <ja...@wordzoo.com>.
[Citation date: Tue, 22 May 2001 15:59:52 -0400]

>>>>> Chris == Chris Thompson <ct...@cthompson.com>

    Chris> I've got a hash %s successfully re tied every request. I'm
    Chris> using it to store a session id and userid with success, so
    Chris> I know it's storing.

In the Behavior section of the Apache::Session man page, you'll find:

  Note that Apache::Session does only a shallow check to see if
  anything has changed.  If nothing changes in the top level tied
  hash, the data will not be updated in the back- ing store.  You
  are encouraged to timestamp the session hash so that it is sure
  to be updated.

Basically, you'll need to either:

  1. Use the 'timestamp' technique suggested above.

  2. Deference your variables a bit before updates.  Instead of:

       $s{$x}->[$y]->{$z} = 5;

     you'll need to use some intermediate variables:

       $q = $s{$x}->[$y];
       $q->{$z} = 5;
       $s{$x} = $q;

RTFM.

-- jared@wordzoo.com

"A hundred thousand lemmings can't be wrong."
        -- attributed to Larry Sheldon, Jr.

Re: Apache::Session not storing changes to hashref

Posted by "Jeffrey W. Baker" <jw...@acm.org>.

On Tue, 22 May 2001, Chris Thompson wrote:

> I'm at wits end, I'm hoping someone can tell me what's wrong.
>
> This is Apache 1.3.19, Redhat 6.2, modperl 1.25, apache::session 1.53
> and MySQL 3.23.36.
>
> (This is also happening inside HTML::Mason 1.03, but I dont think that has
> anything to do with it. I've crossposted to the mason list in case anyone
> there has seen this behavior, but what I'm doing isnt really out of the
> ordinary, so I dont think it's Mason related)

<yak yak>

> That's there because before I did the Dumper, I populated the %s with the
> data I had on the term. Each term is read from Apache::Request into
> @term. (Yes, the orders match)
>
> so I do...
>
>   my $c=0;
>   foreach my $term (@term) {
>    $s{regdomains}->[$c++]->{term} = $term;
>   }

<yak yak>

Check the Apache::Session docs.  Your changes below the toplevel will not
be noticed.  You must either change something at the top level (like a
timestamp or serial number), or you must frob the session object via
tied(%session)->make_modified();

Docs are your friend and I spent a lot of time writing them.

-jwb




Re: Apache::Session not storing changes to hashref

Posted by Cees Hek <ce...@sitesuite.net>.
Apache::Session only does a shallow check of your data structure to see if
it needs to update the database.  If you are only changing values deep
inside a hash structure, A::S will not see the changes, and they will not
be saves.  The man page recommends adding a timestamp to the tied hash and
updating that on every request (ie $s{_timestamp} = time;).

Cees

On Tue, 22 May 2001, Chris Thompson wrote:

> I'm at wits end, I'm hoping someone can tell me what's wrong.
> 
> This is Apache 1.3.19, Redhat 6.2, modperl 1.25, apache::session 1.53
> and MySQL 3.23.36.
> 
> (This is also happening inside HTML::Mason 1.03, but I dont think that has
> anything to do with it. I've crossposted to the mason list in case anyone
> there has seen this behavior, but what I'm doing isnt really out of the
> ordinary, so I dont think it's Mason related)
> 
> I've got a hash %s successfully re tied every request. I'm using it to store
> a session id and userid with success, so I know it's storing.
> 
> Maybe I'm doing too much for A::S but here goes.
> 
> I want an entry in the %s hash that is an array of hashrefs
> 
> so tied-hash -> array -> hash.
> 
> I'm writing this in wizard style, getting one piece of information from the
> client per page. The first step is to get a list of domain names, which I do
> and store in @domain.
> 
> then I do
> 
>   my $c=0;
>   foreach my $dom (@domain) {
>    my $ref = { 'domainname' => $dom,
>                'term' => '',
>                'ns1name' => '',
>                'ns1ip' => '',
>                'ns2name' => '',
>                'ns2ip' => ''
>              };
>    $s{regdomains}->[$c++] = $ref;
>   }
> 
>   this data is all successfully stored in the session.
> 
>   We now move to the second page, and if I do a Data::Dumper on %s, I can
> actually see the above structure as I envisioned it.
> 
> (I'll paraphrase here and not paste the whole dump)
> 
>           'regdomains' => [
>                             {
>                               'ns1name' => '',
>                               'ns2ip' => '',
>                               'domainname' => 'qwert.com',
>                               'term' => '2',
>                               'ns2name' => '',
>                               'ns1ip' => ''
>                             },
> 
> Note that 'term'=> '2'.
> 
> That's there because before I did the Dumper, I populated the %s with the
> data I had on the term. Each term is read from Apache::Request into
> @term. (Yes, the orders match)
> 
> so I do...
> 
>   my $c=0;
>   foreach my $term (@term) {
>    $s{regdomains}->[$c++]->{term} = $term;
>   }
> 
> Then I do the Dumper. You can see the result above. Term is set, and I've
> verified by changing the term per domain name that the data is going in
> correctly.
> 
> Now, as I understand it, the tie is causing any data written into the hash
> to be written to the database.
> 
> The problem is that it's not. When I get to my third page I get four fields
> per domain for the nameservers and assign into the hash with...
> 
>   my $c=0;
>   foreach (@{$s{regdomains}}) {
>    $s{regdomains}->[$c]->{ns1name} = $nsn1[$c];
>    $s{regdomains}->[$c]->{ns1ip} = $nsip1[$c];
>    $s{regdomains}->[$c]->{ns2name} = $nsn2[$c];
>    $s{regdomains}->[$c]->{ns2ip} = $nsip2[$c];
>    $c++;
>   }
> 
> I then do a Dumper and get...
> 
> 
>           'regdomains' => [
>                             {
>                               'ns1name' => 'a',
>                               'ns2ip' => 'd',
>                               'domainname' => 'qwert.com',
>                               'term' => '',
>                               'ns2name' => 'c',
>                               'ns1ip' => 'b'
>                             },
> 
> you'll see that term is now empty. I've watched the db, and reading it's
> cryptic scrawl, I never see any entries for term.
> 
> HELP!
> 
> 
> 

-- 
Cees Hek
SiteSuite Corporation
cees@sitesuite.net