Destructor fixes.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 8 Oct 2009 21:41:24 +0000 (15:41 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 8 Oct 2009 22:16:10 +0000 (16:16 -0600)
Destructors have no access to the session - need to do these tasks in a
function registered via register_shutdown_function().

framework/LoginTasks/lib/Horde/LoginTasks.php
framework/SessionHandler/lib/Horde/SessionHandler.php
framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php
framework/SessionObjects/lib/Horde/SessionObjects.php

index 282a182..8c36cb3 100644 (file)
@@ -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);
index 3fa630e..54812df 100644 (file)
@@ -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();
 
index a82aecd..e68a5d6 100644 (file)
@@ -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);
index e9c6939..8ceb4fb 100644 (file)
@@ -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']) &&