public static function get_session() { if (!isset(MemcacheSession::$instance)) { MemcacheSession::$instance = new MemcacheSession(); } return MemcacheSession::$instance; }
public function init($lt, $rememberMeLifetime) { global $configArray; // Set defaults if nothing set in config file. $host = isset($configArray['Session']['memcache_host']) ? $configArray['Session']['memcache_host'] : 'localhost'; $port = isset($configArray['Session']['memcache_port']) ? $configArray['Session']['memcache_port'] : 11211; $timeout = isset($configArray['Session']['memcache_connection_timeout']) ? $configArray['Session']['memcache_connection_timeout'] : 1; // Connect to Memcache: self::$connection = new Memcache(); if (!@self::$connection->connect($host, $port, $timeout)) { PEAR_Singleton::raiseError(new PEAR_Error("Could not connect to Memcache (host = {$host}, port = {$port}).")); } // Call standard session initialization from this point. parent::init($lt, $rememberMeLifetime); }
{ return $this->enabled; } function read($key) { $cache_key = $this->_buildCacheKey($key); if ($this->enabled) { return $this->lib->get($cache_key); } } function write($key, $val) { global $prefs; if ($this->enabled) { $this->lib->set($this->_buildCacheKey($key), $val, 60 * $prefs['session_lifetime']); } return $this->enabled; } function destroy($key) { if ($this->enabled) { $this->lib->delete($this->_buildCacheKey($key)); } return $this->enabled; } function gc($maxlifetime) { } } $memcache_session = new MemcacheSession(); $memcache_session->_init();