Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

memcached -u memcached -d -m 30 -l 127.0.0.1 -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 127.0.0.1... Connected to localhost. Escape character is '^]'.

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

<?php
$memcache = new Memcache;
$memcache->connect('192.168.1.102', 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";

var_dump($get_result);
?>

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

Warning: Memcache::connect() [memcache.connect]: Can't connect to 192.168.1.102:11211, 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

1 Answer 1

up vote 5 down vote accepted
# memcached -u memcached -d -m 30 -l 127.0.0.1 -p 11211

You'll notice there is "-l 127.0.0.1" 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 127.0.0.1 with 192.168.1.102 and now it working ! –  billyduc Sep 10 '09 at 7:57

Your Answer

 
discard

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.