Stange behaviour: PHP5.2.4 userdefined Sessionhandler in write function

This is a discussion on Stange behaviour: PHP5.2.4 userdefined Sessionhandler in write function within the PHP Language forums, part of the PHP Programming Forums category; Hi group, I found something strange in PHP5.2.4 (on IIS7/Vista). I am working on an app that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-19-2007
Erwin Moller
 
Posts: n/a
Default Stange behaviour: PHP5.2.4 userdefined Sessionhandler in write function

Hi group,

I found something strange in PHP5.2.4 (on IIS7/Vista).

I am working on an app that has been running just fine under heavy load
for over a year at some custumer of mine. (they have PHP5.1 on W2003
Server, ISAPI)

I imported the whole project locally on a slightly more modern version
of PHP 5.2.4 to make a few adjustments.

I needed a custum sessionhandler (via database) in this particular project.

So I have:

session_set_save_handler (
'MySession_open',
'MySession_close',
'MySession_read',
'MySession_write',
'MySession_destroy',
'MySession_gc');

First thing I found locally was that my sessions didn't work.

After some errorlogging (which is not easy in sessionhandlers since you
cannot output via echo to the client, you need to debug via a file), I
found the reason for my trouble was the fact that I lost my $connection
object.

This object is a ADODB object (www.phplens.com/adodb).
I used this particular databaseabstraction layer for years without problems.

Here is the start of my modified session write handler function:

function MySession_write($ses_id, $data) {
global $connection;

$connExists = (isset($connection) ? "exists": "doesn't exist");

// Hack for my version of PHP that somehow destroys connection
if (!isset($connection)){
require ('dbconnect.php');
}

error_log("\ninMySession_write:\$connExists=".$con nExists."\n\$ses_id=$ses_id\n\$data=$data\n\n",3,' C:\inetpub\php5errlog.txt');

..... actual code ...
}

I was surprised to find in C:\inetpub\php5errlog.txt:
in MySession_write:$connExists=doesn't exist
$ses_id=d86415c53f9c9f4125cff6b2725eb61e
$data=userid|i:1;realname|s:18:" CS-Erwin Möller";isadmin|s:1:"Y";

Meaning my $connection was lost somewhere.
I use that same approach (via global $connection) in all other
sessionhandler functions. No problems.
But in the writeroutine it is gone.

This for sure DIDN'T happen on the earlier version of PHP5 at my client.

Thus I ended up adding this stinking piece of code, to re-include the
whole databaseconnection-code:

// Hack for my version of PHP that somehow destroys connection
if (!isset($connection)){
require ('dbconnect.php');
}

Any ideas what is causing this?

I was thinking that PHP was maybe clearing up its connections to the
database first, before calling the session_write routine? Thus
invalidating my $connection? (I am guessing here).

Did anybody see something similar?
Any clues?

Regards,
Erwin Moller
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:43 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0