Loading ...
Sorry, an error occurred while loading the content.

$Session object

Expand Messages
  • Peter Beardsley
    I m trying to learn how to use the $Session object to maintain session state and I m running into a few problems. I want to use it to store a reference to a
    Message 1 of 6 , Feb 28, 2002
    • 0 Attachment
      I'm trying to learn how to use the $Session object to maintain session
      state and I'm running into a few problems. I want to use it to store a
      reference to a complex data structure(It's an arrayref of hashrefs... yes I
      read the docs on this and I'm using it read-only) like so:

      $Session->{'companyrowref'} = Data::GetCompanies();

      The first time I did this it worked fine-- I got my data structure back,
      assinged it to the object and got data out of it fine across requests.

      Then I needed to figure out how to figure out a way to invalidate it for a
      refresh mechanism... I figured a simple undef would do:

      undef( $Session->{'companyrowref'} );

      Now it seems like the hash key is broken, when I try assign to
      'companyrowref' I get this in my error log(even after a server restart):

      [Thu Feb 28 10:57:23 2002] [error] [asp] [18562] [error] sdbm store
      returned -1, errno 22, key "companyrowref" at
      /usr/local/lib/perl5/site_perl/5.6.1/MLDBM.pm line 161. <--> ,
      /usr/local/lib/perl5/site_perl/5.6.1/Apache/ASP.pm line 1556

      So it seems that I shouldn't be undefing my hash key. I tried getting rid
      of it using $Session->{'companyrowref'} = ''; and %{$Session} = (); both to
      no avail. Can someone give me any ideas as to how I should be handling
      this and also how I might be able to get rid of that bad key in MLDBM?

      Thanks,

      Peter Beardsley
      Appropriate Solutions, Inc.
      pbeardsley[AT]appropriatesolutions.com


      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Joshua Chamas
      ... How about these? $Session- { companyrowref } = undef; delete $Session- { companyrowref }; %$Session = (); Do these clear the data correctly? --Josh
      Message 2 of 6 , Feb 28, 2002
      • 0 Attachment
        Peter Beardsley wrote:
        >
        > I'm trying to learn how to use the $Session object to maintain session
        > state and I'm running into a few problems. I want to use it to store a
        > reference to a complex data structure(It's an arrayref of hashrefs... yes I
        > read the docs on this and I'm using it read-only) like so:
        >
        > $Session->{'companyrowref'} = Data::GetCompanies();
        >
        > The first time I did this it worked fine-- I got my data structure back,
        > assinged it to the object and got data out of it fine across requests.
        >
        > Then I needed to figure out how to figure out a way to invalidate it for a
        > refresh mechanism... I figured a simple undef would do:
        >
        > undef( $Session->{'companyrowref'} );
        >

        How about these?

        $Session->{'companyrowref'} = undef;
        delete $Session->{'companyrowref'};
        %$Session = ();

        Do these clear the data correctly?

        --Josh

        _________________________________________________________________
        Joshua Chamas Chamas Enterprises Inc.
        NodeWorks Founder Huntington Beach, CA USA
        http://www.nodeworks.com 1-714-625-4051

        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      • Chris Marschall
        Hello all, I seem to remember reading in this group, that you shouldn t stuff too much data in $Session. Why is this the case? Is is simply performance, and
        Message 3 of 6 , Feb 4, 2004
        • 0 Attachment
          Hello all,

          I seem to remember reading in this group, that you shouldn't stuff too
          much data in $Session. Why is this the case? Is is simply performance,
          and if so how much data can I store in here reasonably.

          The reason that I ask is this:

          I tend to develop using OO, and was wondering if there are any
          ramifications of generating a reasonably complex object (hash structure
          with references to array references and other hash structures, probably
          about 30K of data) and simply storing the pointer to this in the $Session
          object.

          Now when the script actually finishes, does the $Session object in it's
          entirity get dumped to the state directory (I'm assuming that this is the
          case) or does my complex object get kept in memory until the $Session
          object expires; when the $Session object is destroyed, there will be no
          more references to my object and hence it should be garbage collected.

          Any shedding of light on this would be appreciated.

          Regards,

          Chris.

          ---------------------------------------------------------------------
          To unsubscribe, e-mail: asp-unsubscribe@...
          For additional commands, e-mail: asp-help@...
        • Helmut Zeilinger
          Hi Chris, the reason for the data size limit is, that the SDBM hash size limit is 1024 bytes for the key + the value. You can store more data if you use
          Message 4 of 6 , Feb 4, 2004
          • 0 Attachment
            Hi Chris,

            the reason for the data size limit is, that the SDBM hash size
            limit is 1024 bytes for the key + the value.

            You can store more data if you use DB_File or MLDBM::Sync::SDBM_File
            for storing the data.

            But see "man Apache::ASP", Section "State Management" (StateDB).

            Regards

            Helmut

            >
            > I seem to remember reading in this group, that you shouldn't stuff too
            > much data in $Session. Why is this the case? Is is simply performance,
            > and if so how much data can I store in here reasonably.
            >
            > The reason that I ask is this:
            >
            > I tend to develop using OO, and was wondering if there are any
            > ramifications of generating a reasonably complex object (hash structure
            > with references to array references and other hash structures, probably
            > about 30K of data) and simply storing the pointer to this in the $Session
            > object.
            >
            > Now when the script actually finishes, does the $Session object in it's
            > entirity get dumped to the state directory (I'm assuming that this is the
            > case) or does my complex object get kept in memory until the $Session
            > object expires; when the $Session object is destroyed, there will be no
            > more references to my object and hence it should be garbage collected.
            >
            > Any shedding of light on this would be appreciated.
            >
            > Regards,
            >
            > Chris.
            >
            > ---------------------------------------------------------------------
            > To unsubscribe, e-mail: asp-unsubscribe@...
            > For additional commands, e-mail: asp-help@...
            >

            ---------------------------------------------------------------------
            To unsubscribe, e-mail: asp-unsubscribe@...
            For additional commands, e-mail: asp-help@...
          • Josh Chamas
            ... Helmut is correct. I would like to add that since mod_perl & Apache are multi-process, they don t share memory, so all this session state is stored to
            Message 5 of 6 , Feb 4, 2004
            • 0 Attachment
              Helmut Zeilinger wrote:
              > Hi Chris,
              >
              > the reason for the data size limit is, that the SDBM hash size
              > limit is 1024 bytes for the key + the value.
              >
              > You can store more data if you use DB_File or MLDBM::Sync::SDBM_File
              > for storing the data.
              >
              > But see "man Apache::ASP", Section "State Management" (StateDB).
              >
              > Regards
              >
              > Helmut
              >

              Helmut is correct. I would like to add that since mod_perl & Apache
              are multi-process, they don't share memory, so all this session state
              is stored to disk to allow multi-process data sharing. So basically,
              you want to keep the data going to disk lighter, and only store enough
              to allow your objects to be recreated in memory each request via
              constructors, & not serialize the object to disk/$Session fully each
              request/read/write.

              Consider that each time one does:

              $Session->{object} = {};

              you just wrote to disk. Though DB_File holds more than SDBM_File,
              it is much slower to do basic read/write operations for smaller
              bits of data, and accessing large blocks of data is obviously slow.

              Definitely read the MLDBM::Sync man page for a further analysis of this
              which is the internal state manager used for Apache::ASP.

              Regards,

              Josh

              ________________________________________________________________
              Josh Chamas, Founder phone:925-552-0128
              Chamas Enterprises Inc. http://www.chamas.com
              NodeWorks Link Checker http://www.nodeworks.com


              ---------------------------------------------------------------------
              To unsubscribe, e-mail: asp-unsubscribe@...
              For additional commands, e-mail: asp-help@...
            • Chris Marschall
              Gentlemen, Thanks for the prompt feedback. Of course, the lack of shared memory (multi-threading) explains why it would have to commit all state information
              Message 6 of 6 , Feb 4, 2004
              • 0 Attachment
                Gentlemen,

                Thanks for the prompt feedback.

                Of course, the lack of shared memory (multi-threading) explains why it
                would have to commit all state information for each request.

                Thanks also for the DB_File information.

                Much appreciated.

                Regards,

                Chris.

                On Wed, 4 Feb 2004, Josh Chamas wrote:

                > Helmut Zeilinger wrote:
                > > Hi Chris,
                > >
                > > the reason for the data size limit is, that the SDBM hash size
                > > limit is 1024 bytes for the key + the value.
                > >
                > > You can store more data if you use DB_File or MLDBM::Sync::SDBM_File
                > > for storing the data.
                > >
                > > But see "man Apache::ASP", Section "State Management" (StateDB).
                > >
                > > Regards
                > >
                > > Helmut
                > >
                >
                > Helmut is correct. I would like to add that since mod_perl & Apache
                > are multi-process, they don't share memory, so all this session state
                > is stored to disk to allow multi-process data sharing. So basically,
                > you want to keep the data going to disk lighter, and only store enough
                > to allow your objects to be recreated in memory each request via
                > constructors, & not serialize the object to disk/$Session fully each
                > request/read/write.
                >
                > Consider that each time one does:
                >
                > $Session->{object} = {};
                >
                > you just wrote to disk. Though DB_File holds more than SDBM_File,
                > it is much slower to do basic read/write operations for smaller
                > bits of data, and accessing large blocks of data is obviously slow.
                >
                > Definitely read the MLDBM::Sync man page for a further analysis of this
                > which is the internal state manager used for Apache::ASP.
                >
                > Regards,
                >
                > Josh
                >
                > ________________________________________________________________
                > Josh Chamas, Founder phone:925-552-0128
                > Chamas Enterprises Inc. http://www.chamas.com
                > NodeWorks Link Checker http://www.nodeworks.com
                >

                ---------------------------------------------------------------------
                To unsubscribe, e-mail: asp-unsubscribe@...
                For additional commands, e-mail: asp-help@...
              Your message has been successfully submitted and would be delivered to recipients shortly.