PHP Memcached::getServerList() Function
Last Updated :
26 Nov, 2021
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 = '127.0.0.1' ;
$port = 11211;
$memcacheD = new Memcached();
if ( $memcacheD ->addServer( $server , $port )) {
echo "** server added ** \n" ;
}
else {
echo "** issue while creating a server **\n" ;
}
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 = '127.0.0.1' ;
$port = "8000" ;
$memcacheD = new Memcached();
if ( $memcacheD ->addServer( $server , $port )) {
echo "** server added ** \n" ;
}
else {
echo "** issue while creating a server **\n" ;
}
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
Share your thoughts in the comments
Please Login to comment...