function connect(&$err) { if (!function_exists('memcache_pconnect')) { $err = 'Memcache module PECL extension not found!'; return false; } $memcache = new MemCache; if (!is_array($this->hosts)) $this->hosts = array($this->hosts); $failcnt = 0; foreach($this->hosts as $host) { if (!@$memcache->addServer($host,$this->port,true)) { $failcnt += 1; } } if ($failcnt == sizeof($this->hosts)) { $err = 'Can\'t connect to any memcache server'; return false; } $this->_connected = true; $this->_memcache = $memcache; return true; }
private static function _CreateCacheInstance($cluster = 'default') { $cache_instance = new MemCache(); foreach ($GLOBALS['CONFIG_MEMCACHE'][$cluster] as $one) { list($ip, $port, $weight) = explode(':', $one); $a = $cache_instance->addServer($ip, $port, true, $weight, 1, 15, true, array('Memcache', 'FailureCallback')); } $cache_instance->setCompressThreshold(5000); // > 5k then zlib return $cache_instance; }
/** * * @return boolean */ public function disconnect() { if (!$this->isEnabled()) { return false; } return $this->memcache->close(); }
private function buildRedisCache() { if (null === $this->host) { throw new HostShouldBeProvidedException(); } if (null === $this->port) { $this->port = Redis::DEFAULT_PORT; } if (null === $this->timeout) { $this->timeout = Redis::DEFAULT_TIMEOUT; } $this->server->connect($this->host, $this->port, $this->timeout); $this->server->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_PHP); $ro = new \ReflectionObject($this->cacheProvider); $redisProperty = $ro->getProperty('redis'); $redisProperty->setAccessible(true); $redisProperty->setValue($this->cacheProvider, $this->server); }
public static function connect() { $mCache = new MemCache(); $mCache->addServer(new MemCacheServer(kernel::Configuration("memcachedServer"), kernel::Configuration("memcachedPort"))); return $mCache; }
/** * 添加server * @param <type> $servers * @return MemCache */ public function addServer($servers) { $cacheInstance = new MemCache(); foreach ($servers as $server) { $cacheInstance->addServer($server['host'], $server['port'], $server['lasting'], $server['weight'], $server['connectTime'], 15, true, array('Leb_Dao_Memcache', 'failureCallback')); } return $cacheInstance; }