當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


PHP Memcached::getServerList()用法及代碼示例


Memcached::getServerList()函數是PHP中memcached類的內置函數,用於獲取memcache服務器池中的服務器列表。

用法:

public Memcached::getServerList(): array

參數:該函數沒有參數。

返回值:此函數返回一個包含服務器列表的數組。

以下示例程序旨在說明 Memcached::getServerList() 的函數:

示例 1:

PHP


<?php 
    echo "<pre>"; 
      
    // 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()); 
?>

輸出:

**  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


<?php 
  echo "<pre>"; 
  // 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



相關用法


注:本文由純淨天空篩選整理自Shivam.Pradhan大神的英文原創作品 PHP Memcached::getServerList() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。