Cakephp + phpcgi + memcache persistent connection

Source: Internet
Author: User
Cakephp + phpcgi + memcache persistent connection

Problem: php-cgi when the server traffic is lowThe number of connections is abnormal;

# Netstat-anpo | grep 'php-cgi'

416

Further observation shows that all connections are ESTABLISHED by php-cgi and memcache, and the status is ESTABLISHED (normal data transmission status)

Analysis:

According to my colleague Hua Ming, I confirmed that memcache in cakephp uses persistent connections by default. in php-cgi, all established connections will not be closed, therefore, we may find the number of abnormal connections. although apache + php is a persistent connection, after apache is executed, the memcache connection process is automatically killed, so there will be no abnormal connection conditions, only php-cgi will have such problems;

Solution:

Modify the cakephp code to change the default persistent connection to a transient connection:

/Data/www/cakephp/cake/libs/cache/memcache. php

If ($ this->__ Memcache-> addServer ($ host, $ port )){

Is

If ($ this->__ Memcache-> addServer ($ host, $ port,False)){

References:

Http://cakephp.lighthouseapp.com/projects/42648/tickets/1705-cake-138-memcacheengine-does-not-close-connection

Https://github.com/tPl0ch/cakephp/commit/402c4a7a6fb171c59cb445ff7c9f7c16f9f1851f

Http://www.php.net/manual/en/memcache.addserver.php

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.