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