开发者

Memcache localhost connection oddity

When I try to connect to memcache using this code:

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

The call dies with the "Could not connect" error, but if I use localhost's IP:

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

It works! So what's my problem? Well, this new computer is the only development environment I've setup that's been sensitive to that difference. I'm not about to go changing the s开发者_StackOverflowettings on any code for what seems to be a computer specific issue, but I can't figure out what could be causing this behaviour.

I'm running XP, memcached 1.2.4, and wampserver 2. I've checked the hosts file; it does have an entry for localhost, and the dns cache has been flushed... Any ideas?


Running "ping localhost", as Conspicuous Compiler suggested, revealed that localhost was resolving to ::1 rather than 127.0.0.1. This is the correct behaviour for a network using IPv6, but it was this that was confusing memcached. As I didn't require IPv6 at all, I uninstalled it;

Right-click on a Network Connection > Properties > Highlight "Microsoft TCP/IP version 6" > Uninstall

All good again!

Please note; it may be that you can solve the issue less destructively by mapping ::1 to localhost as an entry in your hosts file. I didn't try it...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜