Memcache::connect() [<a href='memcache.connect'>memcache.connect</a>]: Can't connect to localhost:11212, Connection refused (111) in /.../sites/all/modules/memcache/ on line 306.

I'm getting the above error when an anonymous visitor tries to access a 403 page (access denied)... plus, the visitor never receives any page content. If a user is logged in, there is no problem. Likewise, if the anonymous visitor tries to access a normal (non-access-denied) page, there is no problem.

I'm tagging this as a support request, because I may have some configuration error... but Memcache Admin shows it's hitting the cache when I'm monitoring different pages on the site, so I know memcache is working...


geerlingguy’s picture

I've found a couple other sites seem to have similar problems (maybe related, maybe not...):
New York Public Library (google's cache)

A google search brings up a large list of people with memcache seemingly misconfigured...

geerlingguy’s picture

Well, I updated my settings.php to include memcache's file, so my new $conf array is as follows:

    $conf = array (
        // The path to, inside the memcache module folder
      'cache_inc' => './sites/all/modules/memcache/',
      'session_inc' => './sites/all/modules/memcache/',
      'memcache_servers' => array('localhost:11211' => 'default',
                                  'localhost:11212' => 'pages'),
      'memcache_bins' => array('cache_page' => 'pages'),

And now the error goes away... I couldn't find anywhere in the docs a requirement (or even directions) for using the file; maybe this could be added in the readme, or in the project page?

Jeremy’s picture

Has this ever worked for you? If so, what did you change when this started being a problem?

geerlingguy’s picture

It was never working for me until I added the session_inc...

geerlingguy’s picture

I'm having the same problem on another server now - both are running CentOS 5.5, one uses Web Host Manager, the other is a plain-vanilla CentOS server...

I've also tried with another custom memcache connection script, and it's getting the same error. It must be configuration on the server—perhaps something in iptables...

geerlingguy’s picture

Still looking into this problem, and I can't find a solution. I would rather not use memcache's session handling, as it causes problems with a few other modules I'm using, but without it, I get a lot of these connection refused notices, causing my logs to fill up pretty quickly.

[Edit - more research...]

I found this thread on Server Fault, which asks if selinux is enabled (in my case, it's not) - selinux could cause this problem.

I also found this thread, and this prompted me to look up CentOS's iptables wiki page, and I'm now working on reconfiguring iptables on my machine to accept traffic to that port from the local machine...

geerlingguy’s picture

Status: Active » Closed (works as designed)

Well, after a bit more research, it seems that connections are refused when a user tries accessing a page on the site that is already cached - for instance, if a user tries accessing /node/9, but is not logged in (thus, access is denied), then the user is directed to my custom login page, and memcache throws the access denied warning.

This was confusing me mostly because my custom module redirects all users to / if they're not logged in, and I didn't notice that the memcache warnings are likely generated before the redirect happens.

Marking as fixed, but I still wish I could suppress these warnings :)

wozzz7’s picture

Status: Closed (works as designed) » Active

I am getting this message too and my error logs are filling up - is it good practice to use geerlingguy solution in #2 ??

Because the error logs are building up I am getting a lot of problems with the site.

JeffSheltren’s picture

Status: Active » Postponed (maintainer needs more info)

If you're still having this issue, please paste the memcache settings from your settings.php. It'd also be good to get some debug/log messages from memcached itself if possible. Also, which PECL extension are you using?

erikwebb’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)