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