Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm totally new to memcached ! I sucessfully Installed and started memcached with this command in my host A (Ip

memcached -u memcached -d -m 30 -l -p 11211

I also add these entry to iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 11211 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 11211 -j ACCEPT

restarted iptables service and it listened to port 11211

telnet also work !

telnet localhost 11211

Trying Connected to localhost. Escape character is '^]'.

But I connect to this host A from Host B (IP with this script memcached_test.php

$memcache = new Memcache;
$memcache->connect('', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";


When I browser this script in the server at host B ( I recieved this error

Warning: Memcache::connect() [memcache.connect]: Can't connect to, Connection refused (111) in /var/www/memcache_test.php on line 3 Could not connect

Please tell me how to solve this problem!

share|improve this question
up vote 10 down vote accepted
# memcached -u memcached -d -m 30 -l -p 11211

You'll notice there is "-l" in your command line. This tells memcached to only listen on the lo interface. If you want to access it from a remote machine, you need to remove this part of the command line.

share|improve this answer
thank you so much ... I replace with and now it working ! – billyduc Sep 10 '09 at 7:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.