#34430 [NEW]: Custom handler + object destruction
| From: | jpleveille at unimasoft dot com | Date: | Thu, 08 Sep 2005 15:17:32 +0000 |
| Subject: | #34430 [NEW]: Custom handler + object destruction | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-84738@lists.php.net to get a copy of this message | ||
From: jpleveille at unimasoft dot com
Operating system: Windows XP SP2
PHP version: 5.0.5
PHP Bug Type: Session related
Bug description: Custom handler + object destruction
Description:
------------
If this is a not a bug, sorry. But I think the behaviors of script
execution and object destruction changed in PHP 5.0.5 without notice.
I created a session handler which uses a database object to query a MySQL
DB to load/save sessions. The object is a PEAR::DB instance created with
mysqli factory; the session handler is a simple object with methods being
passed to session_set_save_handler(). The session object has a reference
to the database object to query the database.
A problem started to occur when upgrading from PHP 5.0.4 to PHP 5.0.5 on
both Windows (XP SP2) and Linux. On Linux, it is not possible to close a
session using my own session handler because the database object is
already destroyed (read disconnected - the object was still there but not
connected - I suspect the use of OO interface of mysqli in PEAR::DB). On
Windows, this issue occurs only when functions die() or exit() are used.
Additionally, with E_ALL, I have the following error message:
Unknown: A session is active. You cannot change the session module's ini
settings at this time. in Unknown on line 0
Reproduce code:
---------------
My session handler:
class DB_Session
{
private $db; // instance of PEAR::DB(mysqli)
public __construct($db) { $this->db = $db; }
public open($save_path, $session_name); // to open session
public close(); // to close session
public read($id); // to read the session data
public write($id, $sess_data); // to write session data
public destroy($id); // to delete the session in DB
public gc($maxlifetime); // my garbage collector
public start() // to start the session
{
ini_set('session.hash_bits_per_character', 5);
ini_set('session.hash_function', 1); // SHA1
session_set_save_handler(
array($this, "open"),
array($this, "close"),
array($this, "read"),
array($this, "write"),
array($this, "destroy"),
array($this, "gc")
);
session_start();
}
}
$db = PEAR::connect('mysqli://user:pass@host/db');
$session = new DB_Session($db);
// on Linux, $session->write() raises an error (PEAR::DB
// object disconnected)
// this error occurs in Windows when die() or exit is called
Expected result:
----------------
In PHP 5.0.4, the database object is still connected when the session
handler is called to write the session data. I expected the same behavior
in PHP 5.0.5, i.e.:
- database object is created
- session object is created, database object passed to constructor
- session is read (ok)
- script execution ends, session is written (ok)
- session is closed (does nothing, db object might be used elsewhere)
Actual result:
--------------
The script executes correctly, but the session isn't saved because method
write() fails to query database to record new session data. I have the
following behavior:
- database object is created
- session object is created, database object passed to constructor
- session is read (ok)
- script execution ends, session is written (failed - db object
disconnected!)
Note that I encountered this error in Windows ONLY when calling exit() or
die(). I encountered this issue in every PHP script execution using the
custom session handler on Linux (debian sarge).
I know my database object may be destroyed BEFORE my session object, but
it doesn't seem to be the case because I can still access its methods. I
think it has something to do with the mysqli object (returned by
mysqli_connect()) but I'm not sure (I also noticed PEAR::DB(mysqli) isn't
handling the persistent option).
--
Edit bug report at http://bugs.php.net/?id=34430&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34430&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34430&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34430&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=34430&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=34430&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=34430&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=34430&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=34430&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=34430&r=support
Expected behavior: http://bugs.php.net/fix.php?id=34430&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=34430&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=34430&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=34430&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34430&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=34430&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=34430&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=34430&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=34430&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=34430&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=34430&r=mysqlcfg