In php, the Memcached connection times out. Today, we can see that nginx on the server generates a large number of logs, and the prompt PHPWarning: Memcache: connect (): Cantconnectto127.0.0.1: 11211, Connectiontimedout (110) in, later, I saw a large number of logs generated by nginx on the server from today, and prompted PHP Warning: Memcache: connect (): Can \'t connect to 127.0.0.1: 11211, connection timed out (110) in. after several twists and turns, find out the problem.
During a routine check log, we found that a large number of PHP connection Memcached timeout errors were found in the Nginx log, as shown below:
PHP Warning: Memcache: connect (): Can't connect to 127.0.0.1: 11211, Connection timed out (110) in...
Connect to the server and check that the Memcached process runs normally. then, I use a piece of test code to check whether Memcached can be connected normally, and the result is also normal.
So I carefully analyzed the log and found that the error message appeared at intervals, which indicates a certain probability. At this time, I recall that the Session storage path of PHP was directed to Memcached due to architecture issues last week. it may be because this configuration increases the load of Memcached, resulting in a high concurrency, the Memcached connection times out.
Finding the cause is easy to solve. Modify the Memcached startup parameters and add the-c parameter to increase the number of connections. The default value is 1024. you can gradually increase it to find the optimal value. I set it to 2048.
The startup command is:
| The code is as follows: |
|
Memcached-d-m 256-c 2048-l 127.0.0.1-p 11211-u root |
If there are plenty of servers, you can consider distributed memcached clusters to reduce the pressure on a single node. it is said that over 2.5 connections lead to oom bug
Warning: Memcache: connect (): Can \'t connect to 127.0.0.1: 11211, Connection timed out (110) in, later several times...