Solution to Memcached connection timeout problem in php_PHP tutorial

WBOY
Release: 2016-07-13 10:43:05
Original
1358 people have browsed it

Starting today, I found that the nginx of the server generated a lot of logs, and prompted PHP Warning: Memcache::connect(): Can't connect to 127.0.0.1:11211, Connection timed out (110) in. Later, after many twists and turns, I found Something went wrong.

During a routine log check, I found a large number of PHP connection Memcached timeout error messages in the Nginx log, as follows:

PHP Warning: Memcache::connect(): Can't connect to 127.0.0.1:11211, Connection timed out (110) in ...

Connect to the server to check that the Memcached process is running normally. Then I use a test code to check whether Memcached can connect normally, and the result is also normal.

So I analyzed the log carefully and found that the error message appeared at intervals, indicating that there was a certain probability. At this time, I recalled that I had just pointed PHP's Session storage path to Memcached last week due to architectural issues. It may be because this configuration increased the load on Memcached, which caused Memcached to experience connection timeout when the amount of concurrency was high.

It’s easy to solve once you find the cause. Re-adjust the startup parameters of Memcached and add the -c parameter to increase the number of connections. The default is 1024, which can be increased gradually to find the optimal value. I set it to 2048.

The startup command is:

memcached -d -m 256 -c 2048 -l 127.0.0.1 -p 11211 -u root
The code is as follows
 代码如下 复制代码

memcached -d -m 256 -c 2048 -l 127.0.0.1 -p 11211 -u root

Copy code

If the server is sufficient, you can consider a distributed memcached cluster to reduce the pressure on a single node. It is said that 2.5 has an oom bug caused by too many connections http://www.bkjia.com/PHPjc/633195.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/633195.html
TechArticle
Starting today, I found that the server’s nginx generated a large number of logs, and prompted PHP Warning: Memcache::connect(): Can't connect to 127.0.0.1:11211, Connection timed out (110) in, and then several times...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template