4

I have install memcached and when I try a script test like this one :

$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211);
echo $memcache->getVersion();

I recive the nest error :

: Notice: MemcachePool::getversion(): Server 127.0.0.1 (tcp 11211, udp 0) failed with: Network timeout (0) in /var/www/html/admin/test.php on line 62

What could be the problem? I'm new to memcached.

gideon
  • 1,145
  • 2
  • 13
  • 28

3 Answers3

5

Verify listening

Run lsof -i as root and confirm that the memcache daemon is running on the port you listed.

Formatted for sanity:

memcached 16526 corneliu 31u IPv4 207975 0t0 TCP *:memcache (LISTEN) 
memcached 16526 corneliu 32u IPv6 207976 0t0 TCP *:memcache (LISTEN) 
memcached 16526 corneliu 33u IPv4 207979 0t0 UDP *:memcache
memcached 16526 corneliu 34u IPv6 207980 0t0 UDP *:memcache 

So the memcache server is listening on both TCP and UDP for both IPv4 and IPv6. I assume that the /etc/services entry for memcache is port 11211. Service is listening.

Manually verify the server responds to commands

I'd reference this question: https://stackoverflow.com/questions/6045187/memcache-connects-but-doesnt-respond-to-any-command and verify that the server is responding to commands that you send via telnet or netcat. It will probably also be very helpful if you run tcpdump or wireshark to capture the network traffic and actually see what packets are traveling.

Debug things without changing the memcache configuration first. Attempting to change the server's bind address per that question above should be the last thing you do. Let me know your progress.

Jeff Ferland
  • 20,547
  • 2
  • 62
  • 85
  • memcached 16526 corneliu 31u IPv4 207975 0t0 TCP *:memcache (LISTEN) memcached 16526 corneliu 32u IPv6 207976 0t0 TCP *:memcache (LISTEN) memcached 16526 corneliu 33u IPv4 207979 0t0 UDP *:memcache memcached 16526 corneliu 34u IPv6 207980 0t0 UDP *:memcache – bejan corneliu Feb 29 '12 at 13:19
  • anybody, any help ? – bejan corneliu Feb 29 '12 at 13:30
  • ok. i try : telnet 127.0.0.1 11211 and i recive "..command not found"; next i try : memcached -B binary and i recive "faild to listen....address already in use" ; finaly i try like in the link to put de ip of the site and i recive ( in browser ) this error : Warning: Memcache::connect(): Can't connect to 192.99.141.133:11211 – bejan corneliu Feb 29 '12 at 15:03
  • You need to install a functioning client of some kind... netcat or telnet, and use one of them for the first test. The second operation of server parameters changing is supposed to be used for configuring your running instance, not executed on top of it. It is probably the case that you don't yet have the necessary debugging skills required to complete this exercise. Namely, you should recognize that installing a telnet client or netcat is appropriate instead of telling me "command not found." You may want to hire a consultant if you're in a situation with enough load to need memcache. – Jeff Ferland Feb 29 '12 at 15:09
  • Sounds like memcached (or something) is running and listening on port 11211, have you checked your firewall settings? – symcbean Feb 29 '12 at 15:56
  • [root@localhost ~]# /etc/init.d/iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination Chain FORWARD (policy ACCEPT) num target prot opt source destination Chain OUTPUT (policy ACCEPT) num target prot opt source destination – bejan corneliu Mar 01 '12 at 14:42
4

many people had good results with using pconnect instead of connect

$memcache = new Memcache;
$memcache->pconnect('127.0.0.1', 11211);
echo $memcache->getVersion();

more info here http://hostingfu.com/article/memcachepoolget-server-failed-with-network-timeout-possible-fixes

Mik
  • 149
  • 2
  • This is only a workaround; it doesn't solve the actual problem, and neither you nor the person you linked to explain what this does or why it's useful. – Michael Hampton Dec 04 '12 at 17:02
  • sorry for that ... i just wanted to share what i experienced was working for me.. here is some more information about pconnect... http://php.net/manual/en/memcache.pconnect.php – Mik Dec 05 '12 at 08:27
-1

Just start the memcache Daemon by using this command in terminal

memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody

where

  • -m for memory ,
  • -p for port ,
  • -l for ip address of server ,
  • -u for user
alexander.polomodov
  • 1,068
  • 3
  • 10
  • 14