[英]PHP memcache - check if any server is available in pool?
I have the following code: 我有以下代码:
$cluster['local'] = array('host' => '192.168.1.1', 'port' => '11211', 'weight' => 50);
$cluster['local2'] = array('host' => '192.168.1.2', 'port' => '11211', 'weight' => 50);
$this->memcache = new Memcache;
foreach ($this->cluster() as $cluster) {
$this->memcache->addServer($cluster['host'], $cluster['port'], $this->persistent, $cluster['weight'], 10, 10, TRUE , 'failure' );
}
I would like to make a function that checks if any of my servers in my memcache Pool is available. 我想创建一个函数来检查我的memcache池中的任何服务器是否可用。 How could this be done?
怎么可以这样做?
您可以使用Memcache :: getServerStatus检查服务器的状态。
Using fsockopen()
: 使用
fsockopen()
:
$timeout = 1;
$fp = fsockopen('192.168.1.1', 11211, $errno, $errstr, $timeout);
if (is_resource($fp))
{
// connection to 192.168.1.1:11211 successful
fclose($fp);
}
else
{
// failed to connect to 192.168.1.1:11211 within $timeout second(s).
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.