/** * Get global handle for memcache access * * @return object Memcache */ public function get_memcache() { if (!isset($this->memcache)) { // no memcache support in PHP if (!class_exists('Memcache')) { $this->memcache = false; return false; } $this->memcache = new Memcache(); $this->mc_available = 0; // add alll configured hosts to pool $pconnect = $this->config->get('memcache_pconnect', true); foreach ($this->config->get('memcache_hosts', array()) as $host) { list($host, $port) = explode(':', $host); if (!$port) { $port = 11211; } $this->mc_available += intval($this->memcache->addServer($host, $port, $pconnect, 1, 1, 15, false, array($this, 'memcache_failure'))); } // test connection and failover (will result in $this->mc_available == 0 on complete failure) $this->memcache->increment('__CONNECTIONTEST__', 1); // NOP if key doesn't exist if (!$this->mc_available) { $this->memcache = false; } } return $this->memcache; }