PHP Memcached::getServerList()函数
Memcached::getServerList()函数是PHP中 memcached 类的内置函数,用于获取 memcache 服务器池中的服务器列表。
句法:
public Memcached::getServerList(): array
参数:此函数没有参数。
返回值:此函数返回一个包含服务器列表的数组。
下面的程序说明了 Memcached::getServerList()函数:
示例 1:
PHP
";
// Server & port details
$server = '127.0.0.1';
$port = 11211;
// Initiate a new object of memcache
$memcacheD = new Memcached();
// Add server
if ($memcacheD->addServer($server, $port)) {
echo "** server added ** \n";
}
else {
echo "** issue while creating a server **\n";
}
// Get server detail
echo "Server Details :: \n";
var_dump($memcacheD->getServerList());
?>
PHP
";
// Server & port details
$server = '127.0.0.1';
$port = "8000";
// Initiate a new object of memcache
$memcacheD = new Memcached();
// Add server
if ($memcacheD->addServer($server, $port)) {
echo "** server added ** \n";
}
else {
echo "** issue while creating a server **\n";
}
// Get server detail
echo "Server Details :: \n";
var_dump($memcacheD->getServerList());
?>
输出:
** server added **
Server Details ::
array(1) {
[0]=>
array(3) {
["host"]=> string(9) "127.0.0.1"
["port"]=> int(11211)
["type"]=> string(3) "TCP"
}
}
示例2:(创建服务器时出错:因此没有可用列表)
PHP
";
// Server & port details
$server = '127.0.0.1';
$port = "8000";
// Initiate a new object of memcache
$memcacheD = new Memcached();
// Add server
if ($memcacheD->addServer($server, $port)) {
echo "** server added ** \n";
}
else {
echo "** issue while creating a server **\n";
}
// Get server detail
echo "Server Details :: \n";
var_dump($memcacheD->getServerList());
?>
输出:
** server added **
*** issue while creating a server **
Server Details ::
参考: https://www. PHP.net/manual/en/book.memcached。 PHP