in reply to Using Sessions between perl and php.

This does seem a slightly inefficient way to do things. The PHP code has to exec a perl script to set/retrieve a session value (or did I miss something?).

Wouldn't storing each variable in the table as a seperate row (session_id, var_name, value) work?

gav^

  • Comment on Re: Using Sessions between perl and php.

Replies are listed 'Best First'.
Re: Re: Using Sessions between perl and php.
by jryan (Vicar) on Jan 20, 2002 at 12:19 UTC
    You did miss something: a very large part of the whole process. The php script has to call the perl script to de-serialize the Storable'd data (raw Storable'ized data isn't exactly the nicest to work with) and return it in a php-style serialized form that the php side can work with.

      I was thinking of having a table that goes like:

      session_id var_name value ---------------------------------------- asdijhufio4 user_id 1 asdijhufio4 state 55 fddffff0012 new_user 1 dfdfgeret44 username 'bob'
      And then it is just a matter of doing a 'SELECT var_name, value FROM session where session_id = ?'

      I would think the performance of this would be a lot better than the way you serialize your data.

      Update:It is possible to store the hash in a MySQL blob using \0 as a seperator. This may work better if you don't want to have multiple rows per session.

      Hope this helps...

      gav^

        While a method like this is pretty commonly used in home rolled session systems (and works well enough), there is something that Apache::Session allows you to do via using Storable that you can't do with this mechanism.

        Arbitrary data structures.

        What happens when the session information I need to store goes beyond simple key value pairs? What if I have something like:

        # assume $session is via Apache::Session $session->{'email_targets'} = { "john@doe.com" => { 'first_name' => 'John', 'last_name' => 'Doe' }, "jane@doe.com" => { 'first_name' => 'Jane', 'last_name' => 'Doe' } };

        HTH

        /\/\averick
        perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

      I think gav^ is saying that just that should be avoidable. And I agree; rather than freezing/thawing a hash, one could, I think, choose to store a hash as a series of rows containing a key name and the value, each. Unless I'm still overlooking something important - but I can't seem to find anything such.

      Makeshifts last the longest.