Commit 49bc60f9 authored by Yaju Mahida's avatar Yaju Mahida Committed by Robert Lyon
Browse files

Bug 1792272: Better check for memcached server



behatnotneeded

Change-Id: I9a5799fd88286a36f607624924d625e2507dc08f
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent d2bab9b8
......@@ -104,10 +104,18 @@ class Session {
$servers = preg_replace('#tcp://#', '', $memcacheservers);
foreach (explode(',', $servers) as $server) {
list($destination, $port) = explode(':', $server);
$nc = 'nc -z ' . $destination . ' ' . $port;
$status = exec($nc, $out, $fail);
if ($fail === 1) {
// if server has 'nc' command but can't reach the server:port
$memcached = new Memcached;
if (!empty($destination) && !empty($port)) {
$memcached->addServer($destination, $port);
// addServer doesn't make a connection to the server
// but if the server is added, but not running pid will be -1
$server_stats = $memcached->getStats();
if ($server_stats[$destination . ":" . $port]['pid'] <= 0) {
// can't reach the destination:port
throw new ConfigSanityException(get_string('nomemcachedserver', 'error', $server));
}
}
else {
throw new ConfigSanityException(get_string('nomemcachedserver', 'error', $server));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment