Friday, October 17, 2025
HomeLanguagesPHP Memcached::getServerList() Function

PHP Memcached::getServerList() Function

The Memcached::getServerList() function is an inbuilt function of memcached class in PHP which is used to get the list of the servers in the pool of memcache server.

Syntax:

public Memcached::getServerList(): array

Parameters: This function has no parameters.

Return Value: This function returns an array that consists a list of the servers.

Below program illustrate the Memcached::getServerList() function:

Example 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());
?>


Output:

**  server added **
Server Details ::
array(1) {
[0]=>
array(3) {
  ["host"]=>  string(9) "127.0.0.1"
 ["port"]=>  int(11211)
  ["type"]=>  string(3) "TCP"
}
}

Example 2: (error while creating server :hence no list available)

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());
?>


Output:

**  server added **
*** issue while creating a server **
Server Details ::

Reference: https://www.php.net/manual/en/book.memcached.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS