IPv6 服务开启时 PHP 连接 memcached 失败的原因
该文章根据 CC-BY-4.0 协议发表,转载请遵循该协议。
本文地址:https://fenying.net/post/2014/07/30/ipv6-conflicts-about-mencached/
之前一直用 127.0.0.1 链接 memcached ,最近偷懒改用APMServ搭建服务器,结果用 localhost 却发现怎么也无法接通 memcached。查了许久发现是 IPv6 的问题。附上原因。
On my Debian Squeeze system I was getting WRITE FAILURE errors. After debugging and finally tcpdump it seems that the problem was me adding the server ’localhost’, which resolved to ‘::1’ (ipv6) while the default memcached server on debian only listens to ‘127.0.0.1’ (ipv4). DNS automatically prefers ipv6 over ipv4.
I added the server ‘127.0.0.1’ instead and everything worked. You could also disable ipv6 or have memcached listen on ::1
By Robbie De Lise (2 years ago)
即是说,memcached 默认监听 127.0.0.1 ,如果要支持 IPv6,则必须监听 ::1 。而在某些系统开了 IPv6 支持以后,localhost 就被自动指向了 ::1,即时修改 hosts 文件也无法改变。(Windows 8.1 x64 Pro 为例,关掉 IPv6 服务即可解决)