/** * 连接到缓存服务 * @return bool */ public function connect() { if ($this->cache === null) { $this->cache = $this->getMemcache(); if (!is_array($this->host)) { $this->host = array($this->host); } foreach ($this->host as $server_address) { if (strpos($server_address, ':') === false) { $host = $server_address; $port = 11211; } else { $strs = explode(':', $server_address); $host = $strs[0]; $port = $strs[1] ? $strs[1] : 11211; } $re = $this->cache->addServer($host, $port); if ($re === false) { $this->logger->writeFatal("failed to add memcache server {$server_address}"); } } return $re; } return true; }