Original php::memcached Long Link analysis

Source: Internet
Author: User

To turn long link support on or off, refer to: http://leeon.me/a/php-memcached

Short-chain experimental scenario test code: 1.php

<?PHP$MC = new Memcached (); $mc->setoption (Memcached::opt_libketama_compatible, true); $MC->addservers ( Array (        array (' 10.75.31.39 ', 60000),);p Rint_r ($MC->getstats ()); Sleep (2); >

Long-chain experimental scenario test code: 2.php

<?PHP$MC = new Memcached (' MC '); $MC->setoption (Memcached::opt_libketama_compatible, true); if (!count ($MC Getserverlist ()) {    $MC->addservers (Array (        ' 10.75.31.39 ', 60000),)    )} Print_r ($MC->getstats ()); Sleep (2); >

Environment:

nginx+phpfpm

PHPFPM static mode, single process.

A experimental process:

1. Access the Curl http://127.0.0.1/1.php, etc. output.

2. When the first step has output, the other window NETSTAT-ANPT | grep:60000.

The conclusion is that each visit will create a new link to the backend resource.

B Experimental Process:

1. Access the Curl http://127.0.0.1/2.php, etc. output.

2. When the first step has output, the other window NETSTAT-ANPT | grep:60000.

The conclusion is that each time you visit, the same link will be created for accessing the backend resources.

Finally, note that even if the request ends, you can still see the 6000-port link until the PHP-FPM process is recycled. Theoretically, idle links are not released.

If you are worried about stepping on a pit, you can add the code to the official Memcached::quit ().

Resources:

http://php.net/manual/zh/memcached.getstats.php

Http://haili.me/archives/530.html

Http://leeon.me/a/php-memcached

Related Article

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.