Skip to content

Commit 94554b9

Browse files
author
Mohammed Karim
committed
Added check for Memcached connection.
1 parent 5fed4d7 commit 94554b9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

system/Cache/Handlers/MemcachedHandler.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,20 @@ public function initialize()
128128
$this->memcached->setOption(\Memcached::OPT_BINARY_PROTOCOL, true);
129129
}
130130

131-
// TODO: check if we can connect to the server
132-
133131
// Add server
134132
$this->memcached->addServer(
135133
$this->config['host'], $this->config['port'], $this->config['weight']
136134
);
135+
136+
// attempt to get status of servers
137+
$stats = $this->memcached->getStats();
138+
139+
// $stats should be an associate array with a key in the format of host:port.
140+
// If it doesn't have the key, we know the server is not working as expected.
141+
if( !isset($stats[$this->config['host']. ':' .$this->config['port']]) )
142+
{
143+
throw new CriticalError('Cache: Memcached connection failed.');
144+
}
137145
}
138146
elseif (class_exists('\Memcache'))
139147
{

0 commit comments

Comments
 (0)