protected function getConnection()
{
if (!static::isSupported()) {
throw new \RuntimeException('Memcached Extension is not available');
}
$app = Factory::getApplication();
$host = $app->get('memcached_server_host', 'localhost');
$port = $app->get('memcached_server_port', 11211);
if ($app->get('memcached_persist', true)) {
static::$_db = new \Memcached($this->_hash);
$servers = static::$_db->getServerList();
if ($servers && ($servers[0]['host'] != $host || $servers[0]['port'] != $port)) {
static::$_db->resetServerList();
$servers = array();
}
if (!$servers) {
static::$_db->addServer($host, $port);
}
} else {
static::$_db = new \Memcached();
static::$_db->addServer($host, $port);
}
static::$_db->setOption(\Memcached::OPT_COMPRESSION, $this->_compress);
$stats = static::$_db->getStats();
$result = !empty($stats["{$host}:{$port}"]) && $stats["{$host}:{$port}"]['pid'] > 0;
if (!$result) {
static::$_db = null;
throw new CacheConnectingException('Could not connect to memcached server');
}
}