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!

1 Answer 1

# 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.

  • thank you so much ... I replace with and now it working !
    – billyduc
    Sep 10, 2009 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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