PHP内存缓存 - 检查池中是否有可用的服务器?

Ind*_*ial 5 php memcached libmemcache

我有以下代码:

$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' );
}
Run Code Online (Sandbox Code Playgroud)

我想创建一个函数来检查我的memcache池中的任何服务器是否可用.怎么可以这样做?

sal*_*the 5

您可以使用Memcache :: getServerStatus检查服务器的状态.

  • 我们最终使用"memcache :: getExtendedStats()",因为我们发现getServerStatus有点不可靠.getExtendedStatus似乎总是实时提供正确的服务器状态. (2认同)