Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MemcachePool::get(): Server localhost (tcp 11211, udp 0) failed with: Network timeout

I have been working with Memcache and PHP for a long time and was everything great but now I have been getting this error after every 10 to 15 minutes.

MemcachePool::get(): Server localhost (tcp 11211, udp 0) failed with: Network timeout

I thought it might be due to Firewall or something like that so I turned of my Firewall but yet didn't stop giving this message.

After every error I have to restart my memcache.

And it's Memcache not with D on windows 7 machine with PHP 5.4 MSVC9 TS version. I can not understand what to do now with this Network Timeout issue. What can be done to solve this.

Currently, currently I have only one local machine with windows 7 so cannot make a cluster of Memcache or install Memcache(D).

Unsure if it is a memcache Daemon or client issue.

like image 886
Airy Avatar asked Apr 23 '14 11:04

Airy


People also ask

How to close a Memcached connection in PECL?

(PECL memcache >= 0.2.0) Memcache::connect () establishes a connection to the memcached server. The connection, which was opened using Memcache::connect () will be automatically closed at the end of script execution. Also you can close it with Memcache::close () . Also you can use memcache_connect () function.

How do I connect to memcached using sockets?

Point to the host where memcached is listening for connections. This parameter may also specify other transports like unix:///path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0 . Point to the port where memcached is listening for connections. Set this parameter to 0 when using UNIX domain sockets.

What to do if Memcached is not working?

If memcached is not working, calling memcache_connect ( ) throws a notice AND a warning (and returns false as expected).

What does $Memcache->connect () == False do?

Using ($memCache->connect () == false) will wait for a timeout if it can't connect. If you got a high-traffic site this may not be an option. So when the server is down, you may want to avoid waiting for this timeout on every request and instead try to reconnect only once every X seconds.


1 Answers

I had the same issue, with php on Windows 10 and Memcached installed on Ubuntu (running in the Windows Subsystem for Linux)

Im my case, the problem was that localhost resolves to [::1]:

>ping localhost
Pinging SURFACE-PRO-FRA [::1] with 32 bytes of data:

And Memcached by default listens only on 127.0.0.1.

To solve the issue, you can make Memcached listens also on the ipv6:

$ sudo vi /etc/memcached.conf

Replace

-l 127.0.0.1

with:

-l 127.0.0.1,::1

And then

sudo service memcached restart

Or alternatively, make your app connect to 127.0.0.1 instead of localhost.

like image 186
the_nuts Avatar answered Sep 28 '22 22:09

the_nuts