From: Michael M Slusarz Date: Thu, 8 Oct 2009 21:41:24 +0000 (-0600) Subject: Destructor fixes. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=256b9470167dc920467527249a50cc3f68c1db8a;p=horde.git Destructor fixes. Destructors have no access to the session - need to do these tasks in a function registered via register_shutdown_function(). --- diff --git a/framework/LoginTasks/lib/Horde/LoginTasks.php b/framework/LoginTasks/lib/Horde/LoginTasks.php index 282a18296..8c36cb3be 100644 --- a/framework/LoginTasks/lib/Horde/LoginTasks.php +++ b/framework/LoginTasks/lib/Horde/LoginTasks.php @@ -96,12 +96,14 @@ class Horde_LoginTasks if (empty($this->_tasklist)) { $this->_createTaskList(); } + + register_shutdown_function(array($this, 'shutdown')); } /** - * Destructor. + * Tasks to run on session shutdown. */ - public function __destruct() + public function shutdown() { if (isset($this->_tasklist)) { $_SESSION['horde_logintasks'][$this->_app] = serialize($this->_tasklist); diff --git a/framework/SessionHandler/lib/Horde/SessionHandler.php b/framework/SessionHandler/lib/Horde/SessionHandler.php index 3fa630e9e..54812dffe 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler.php @@ -128,10 +128,11 @@ class Horde_SessionHandler protected function __construct($params = array()) { $this->_params = $params; + register_shutdown_function(array($this, 'shutdown')); } /** - * Destructor. + * Shutdown function. * * Used to determine if we need to write the session to avoid a session * timeout, even though the session is unchanged. @@ -142,7 +143,7 @@ class Horde_SessionHandler * server via a periodic mechanism (think folder refreshing in IMP) that * we will catch this refresh. */ - public function __destruct() + public function shutdown() { $curr_time = time(); diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php b/framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php index a82aecdbe..e68a5d651 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php @@ -89,18 +89,10 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler if (empty($this->_params['track_lifetime'])) { $this->_params['track_lifetime'] = ini_get('session.gc_maxlifetime'); } - } - /** - * Destructor. - */ - public function __destruct() - { if (!empty($this->_params['track']) && (rand(0, 999) == 0)) { - $this->_trackGC(); + register_shutdown_function(array($this, 'trackGC')); } - - parent::__destruct(); } /** @@ -301,7 +293,7 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler throw $e; } - $this->_trackGC(); + $this->trackGC(); $ids = $this->_memcache->get($this->_trackID); return ($ids === false) ? array() : array_keys($ids); @@ -325,7 +317,7 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler /** * Do garbage collection for session tracking information. */ - protected function _trackGC() + public function trackGC() { $this->_memcache->lock($this->_trackID); $ids = $this->_memcache->get($this->_trackID); diff --git a/framework/SessionObjects/lib/Horde/SessionObjects.php b/framework/SessionObjects/lib/Horde/SessionObjects.php index e9c693909..8ceb4fba1 100644 --- a/framework/SessionObjects/lib/Horde/SessionObjects.php +++ b/framework/SessionObjects/lib/Horde/SessionObjects.php @@ -90,12 +90,14 @@ class Horde_SessionObjects if (isset($params['size']) && is_int($params['size'])) { $this->_size = $params['size']; } + + register_shutdown_function(array($this, 'shutdown')); } /** - * Destructor. + * Tasks to run on shutdown. */ - public function __destruct() + public function shutdown() { /* Prune old entries. */ if (isset($_SESSION[$this->_name]['__prune']) &&