note 104104 added to function.session-set-save-handler

From: Date: Mon, 23 May 2011 12:12:44 +0000
Subject: note 104104 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-179951@lists.php.net to get a copy of this message
I have solved problem with session handler, which needs some other objects (for example DB access object), with register_shutdown_function. Just calling <?php register_shutdown_function('session_write_close'); ?> solved my problem. Shutdown functions are called before object destructors. If you use class for session handling (my prefered way), you can call register_shutdown_function in constructor and you must not mess your code in another place. Example: <?php class SessionHandler { protected $_db; public function __construct(PDO $db) { $this->_db = $db; register_shutdown_function('session_write_close'); } function open($save_path, $session_name) { } function close() { } function read($id) { } function write($id, $sess_data) { } function destroy($id) { } function gc($maxlifetime) { } } ?> ---- Server IP: 147.32.160.17 Probable Submitter: 62.84.131.138 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php Edit -- https://master.php.net/note/edit/104104 Del: integrated -- https://master.php.net/note/delete/104104/integrated Del: useless -- https://master.php.net/note/delete/104104/useless Del: bad code -- https://master.php.net/note/delete/104104/bad+code Del: spam -- https://master.php.net/note/delete/104104/spam Del: non-english -- https://master.php.net/note/delete/104104/non-english Del: in docs -- https://master.php.net/note/delete/104104/in+docs Del: other reasons-- https://master.php.net/note/delete/104104 Reject -- https://master.php.net/note/reject/104104 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179951) next »