memcache_connect() [function.memcache-connect]: Can’t connect to localhost:11211

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

  • Multiple memcache instances/servers on windows
  • Facebook Error Message: Requires valid next URL.
  • Cache-Control: post-check, pre-check
  • Drupal 5 Views Module Breaks Block Administration
  • best self written PHP function. ever.
  • 

    4 Responses (Add Your Comment)

    1. It works! Thanks a lot

    2. 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 ;-)

    3. Thanks,Kalle..I’ve connected the server by localhost without error..Just modify the the hosts file.

    4. class main extends Memcache{
      function main(){
      $this->connect(‘localhost’,11211);
      }

      }

    Leave a Reply

    Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Archives

    Twitter!