ID: 27555 Comment by: php at mike2k dot com Reported By: jaanus at heeringson dot com Status: No Feedback Bug Type: Documentation problem Operating System: Linux 2.4.24 PHP Version: 5CVS-2004-03-10 (dev) Assigned To: helly New Comment:
This is still a bug. I just upgraded to PHP 5.1.1, using a custom session handler with mysqli, and this is a problem. It appears this is a workaround, albeit I don't think this should be required to function as it did before. I use procedural code, and not object oriented code, so having __destruct handlers do not help me. register_shutdown_function('session_write_close'); Here's my [very simple] session handler. Note db_query() is a simple wrapper for mysqli_query() and handles all the connection details internally. function session_close() { return true; } function session_die($id) { db_query("DELETE FROM session WHERE ID='$id'"); return true; } function session_gc($maxlifetime) { return true; } function session_open($path,$name) { return true; } function session_read($id) { $dchk = db_query("SELECT data FROM session WHERE ID='$id'"); if(db_numrows($dchk) == 1) { if(!isset($_SESSION['row'])) { $_SESSION['row'] = 1; } list($data) = db_rows($dchk); return base64_decode($data); } else { return ""; } db_free($dchk); return true; } function session_write($id,$data) { global $visitor; $data = base64_encode($data); if(!isset($_SESSION['row'])) { db_query("INSERT IGNORE INTO session (ID,data,accessed) VALUES('$id','$data',UNIX_TIMESTAMP(NOW()))"); } else { db_query("UPDATE session SET data='$data',accessed=UNIX_TIMESTAMP(NOW()) WHERE ID='$id'"); } return true; } (fyi: I have a cronjob that does garbage collection based on the "accessed" column) I still think this is a bug, I don't see why this was changed. Previous Comments: ------------------------------------------------------------------------ [2005-11-20 16:43:47] lists at cyberlot dot net How about register_shutdown_function This is affected also, This isn't something you can just "Document" away. Basically your saying any user made or php made object is useless during the shutdown phase of php. php5 is supposed to bring object programming close to php and this steps all over it. Every single object related function, class, extension has now been made useless/impossible to call during shutdown be in within a session or in a use defined shutdown function. ------------------------------------------------------------------------ [2005-11-09 17:35:17] phpbugs at dubr dot com Why is this being considered a documentation bug? It clearly is a PHP bug and needs to be fixed. ------------------------------------------------------------------------ [2005-10-05 10:24:39] richard dot quadling at bandvulc dot co dot uk One of the real issues here is that the destruction of objects created by the user is not in a logically sequence. Having to manually free objects is sort of correct as relying on automated clearing/garbage collection can only, at best, guess the order in which things should be destroyed. So, assuming somehow there was a way to determine the order of destruction, what happens when you have object interdependance. Say, linking SESSION and DB. DB needs session details to know what the user is, but SESSION needs DB to update status of user. If you DON'T use __desrtuct() at all and use normal methods you HAVE to decide which goes first (which is a better choice than letting the system guess), but requires more work. I don't think there is an easy solution. Richard. ------------------------------------------------------------------------ [2005-10-04 23:59:04] iquito at gmx dot ch I agree, this behaviour makes no sense at all and has to be classified as a bug. Of what use is a shutdown-function, if everything has already been shut down beforehand? Especially the connection to the database is normally very important for everything. I use the register_shutdown-function to destruct all my classes in the correct order at the end of the script, so I don't have to rely on PHP to kill them in the correct order. This makes a lot of sense if you don't know where your script will end exactly. ------------------------------------------------------------------------ [2005-07-24 08:24:43] jasper at bryant-greene dot name This is definitely a bug, and needs to be fixed. As has been mentioned before, all user-definable methods need to have all resources available to them, including the session module, mysqli module, etc. Rather than just saying "the destructor is called too late in the shutdown process" and leaving it at that, why not fix it? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/27555 -- Edit this bug report at http://bugs.php.net/?id=27555&edit=1