Add a distributed number of memcached servers

Source: Internet
Author: User
Tags memcached

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.

  1. 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.
    1. array Memcache::getStats ([string $type [,int $slabid [,int $limit =100]]]) //获取当前服务器的运行状态
  1. <?php
  2. $memcache_obj =newMemcache;
  3. $memcache_obj->addServer(‘127.0.0.1‘,11211);
  4. var_dump($memcache_obj->getStats());
  5. ?>
2.
    1. array Memcache::getExtendedStats ([string $type [,int $slabid [,int $limit =100]]]) //获取所有服务器扩展状态信息
  1. <?php
  2. $memcache_obj =newMemcache;
  3. //返回一个二维关联数组的服务器统计信息或者在失败时返回 FALSE
  4. $memcache_obj -> addServer (‘memcache_host‘,11211);
  5. $memcache_obj -> addServer (‘failed_host‘,11211);
  6. $stats = $memcache_obj -> getExtendedStats ();
  7. print_r ( $stats );
  8. ?>
3.
    1. intMemcache::getServerStatus (string $host [,int $port =11211])//输入主机和端口信息来获取相应的服务器状态信息
  1. <?php
  2. /* OO API */
  3. $memcache =newMemcache;
  4. $memcache -> addServer (‘memcache_host‘,11211);
  5. echo $memcache -> getServerStatus (‘memcache_host‘,11211);
  6. /* procedural API */
  7. $memcache = memcache_connect (‘memcache_host‘,11211);
  8. echo memcache_get_server_status ( $memcache ,‘memcache_host‘,11211);
  9. ?>

Add a distributed number of memcached servers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.