memcache_connect() [function.memcache-connect]: Can’t connect to localhost:11211
May 11th, 2009 • memcache, memcached, php, snippets
Encountered this error? It could be as simple as switching the host from localhost to 127.0.0.1
before:
<?php
$memcache_obj = memcache_connect('localhost', 11211);
after:
<?php
$memcache_obj = memcache_connect('127.0.0.1', 11211);
You might also want to look at these posts
4 Responses (Add Your Comment)
-
spaniard June 9, 2009at 4:30 pm
-
Kalle June 6, 2010at 2:08 am
This occured on Windows right? If so then its because localhost isnt resolved to 127.0.0.1 by PHP if localhost is defined to both an IPv4 and IPv6 alias in the host file
-
Thanks,Kalle..I’ve connected the server by localhost without error..Just modify the the hosts file.
-
class main extends Memcache{
function main(){
$this->connect(‘localhost’,11211);
}}
It works! Thanks a lot