If you have more than one memcached server side, it is best to use memcache::addserver () to connect the service Frontend. instead of Memcache::connect () to connect to the memcached server, the PHP client uses the server pool to assign keys to different servers based on the algorithm.
BOOLMemcache::Addserver(string$host[,int$port=11211[,BOOL$persistent[,int$weight[,int$timeout[,int$retry _interval[,BOOL$status[,Callback $failure _callback[,int$timeoutms]]]]]]]])
The first parameter $host: Represents the address of the server, the second parameter $port: Represents a port, the third parameter $persistent: Indicates whether it is a persistent connection, the default is true, and the fourth parameter $weight: Represents the weight of this server on all servers The fifth parameter $timeout: Indicates the duration of the connection; the sixth parameter $Retry_interval: Indicates the interval between connection retries, the default is 15, and a setting of 1 means no retries;The seventh parameter $status: used to control the server's online status;
Eighth parameter $failure_callback: allows you to set a callback function to handle error messages.Get status information for the server:1.
array Memcache::getStats ([string $type [,int $slabid [,int $limit =100]]]) //获取当前服务器的运行状态
<?php
$memcache_obj =newMemcache;
$memcache_obj->addServer(‘127.0.0.1‘,11211);
var_dump($memcache_obj->getStats());
?>
2.
array Memcache::getExtendedStats ([string $type [,int $slabid [,int $limit =100]]]) //获取所有服务器扩展状态信息
<?php
$memcache_obj =newMemcache;
//返回一个二维关联数组的服务器统计信息或者在失败时返回 FALSE
$memcache_obj -> addServer (‘memcache_host‘,11211);
$memcache_obj -> addServer (‘failed_host‘,11211);
$stats = $memcache_obj -> getExtendedStats ();
print_r ( $stats );
?>
3.
intMemcache::getServerStatus (string $host [,int $port =11211])//输入主机和端口信息来获取相应的服务器状态信息
<?php
/* OO API */
$memcache =newMemcache;
$memcache -> addServer (‘memcache_host‘,11211);
echo $memcache -> getServerStatus (‘memcache_host‘,11211);
/* procedural API */
$memcache = memcache_connect (‘memcache_host‘,11211);
echo memcache_get_server_status ( $memcache ,‘memcache_host‘,11211);
?>
Add a distributed number of memcached servers