in reply to Using Sessions between perl and php.

I think the problem you guys are failing to understand is that the Apache::Session modules use Storable to serialize the data structures, and stores the data in a very precise way. It has nothing to do with me. Apache::Session is very complex, and handles many issues that I would most likely botch if I tried to roll my own Session handling module. Hence, I didn't. Besides, even if I could force the perl side to act like I want, I would still have to worry about the PHP side. PHP has a very bizarre method of serialization - and I can't change that, it is done internally. I had to cater to one or the other, and I chose to cater to perl.

Update:  This is from Steve, my partner, perhaps it will clear some things up:

Ok, here's the deal. First note that Apache::Session handles most of the saving sessions itself. Admittedly, we did not have to use Apache::Session, but that would mean we would have to write our own Perl session handler, and documentation for it (since jryan and I would not be the primary programmers using the system.) Also note that there were time constraints and no time to write our own complete session handling system and document it. So, the goal was to get **Apache::Session** to work with the PHP sessions. I admit that this isn't an optimal solution, but it works.

Now, Apache::Session takes the session data, serializes it with Storable and then stores it in a MySQL database that has an exact structure that MUST be followed. As far as I could tell, there was no way to modify the way this happened, and if there was, it would not be as easy as modifying the way PHP stores the data.

PHP, on the other hand, provides and easy method to change the way the data is stored. With PHP, it would be possible to have a MySQL table with columns for each variable, and if we were just using PHP, that is what we would have used.

I hope this clears some things up,
Steve

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

Replies are listed 'Best First'.
Re: Re: Using Sessions between perl and php.
by gav^ (Curate) on Jan 21, 2002 at 05:59 UTC

    Ok, I'll have to try and explain things better. I know how Apache::Session works and I know that it uses Storable to serialize data types to store in the database.

    What I am trying to say, have you thought that using Apache::Session is maybe the best possible solution to your problem?

    Looking at your documentation (and pointed out by Screamer) you can't use arbitrary data structures. I'm not sure where this limitation comes from but it means that you don't need the flexibility gained by using Storable.

    From your PHP code, it seems that you have to exec a perl script every time you read or write a variable. This seems very inefficient to me.

    I don't think it would be to hard, I had a quick look at the source for Apache::Session::MySQL and you can probably work from this and it's subclasses (reusing the one for locking etc) to create an Apache::Session module that doesn't use Storable.

    gav^

      You are completely missing the whole point of this: IT IS NOT PURE PERL. Its not. Really.

      We used Apache::Session because it worked. It works well. PHP sessions also worked well for us. These two systems were already in place.

      Now, we needed them to talk to each other. PHP provides a method to the default session handling functions. Rather than screw with Apache::Session::MySQL (of which we already had a bitch of a time getting installed), we decided the best route to take was to take advantage of PHP's overridable functions. So we did. The key part here (which you seem to disagree with, probably because you haven't researched this very deeply), is that we needed a way to take the php-serialized data and convert it to perl-serialized data.

      Thats where the perl script that the php script calls comes in. A php-serialized associative array is passed as a command line argument. A perl module deserializes this structure into a hash. The hash is then serialized with Storable. This string is then updated into the sessions database. A reverse process is done when the session data is extracted. Perl, on the other hand, simply grabs the data using the normal Apache::Session::MySQL.

      Yes, its a bit odd, but then it isn't a very normal task. Using our method, pure perl scripts can still take advantage of the full power of Storable, AND we didn't have to have a hacked version of Apache::Session::MySQL in order to get it to work. I fail to see how your method is any easier ours...