There is a discrepancy in the way the memcache servers and their stats are built up in memcache_admin_stats() when the servers connect with Unix sockets. They key returned by dmemcache_stats() includes the port number 0 even though it shouldn't be included in the memcache_servers variable.

The simplest fix seems to be to add ':0' to the $server variable if it represents a Unix socket.

Members fund testing for the Drupal project. Drupal Association Learn more


Island Usurper’s picture

Ha, I forgot to describe what the problem is. The stats page shows the "Failed to connect to server at unix:///tmp/memcached.sock." message, but it still has numbers in the Total column. Everything under the actual server just shows up as 0, but it's obviously finding numbers somewhere.

unitedwallabies’s picture

This fix helped me as well. Thank you.

My version of the patch uses substr instead of strpos -- because strpos() looks through the entire server name.

Both fixes appear to be work-arounds, of course, until the maintainer implements it properly.

unitedwallabies’s picture

Duh... Even better is to use strncmp().

cn_gd’s picture

if you're using PECL Memcached should use patch in :

adammalone’s picture

Status: Active » Needs review

The patch in #3 works for me.

Could this issue and be merged?

Phizes’s picture

Status: Needs review » Needs work

With regards to comment #5: The 2 issues are currently dealing with different parts of the various Memcached and sockets functionality troubles.

#1690130: Memcache fails to connect when using Unix sockets and PECL Memcached is only dealing with the memcache module and PECL memcached, this issue is dealing with the memcache_admin module (which is a sub-module that comes with the Drupal memcache module) and PECL memcache.

Pecl memcache is a seperate project to PECL memcached, the presence or lack of the d is significant as it means that a different string needs to be passed to the respective addServer methods. ('unix:///path/to/socket' for PECL memcache versus '/path/to/socket' for PECL memcached) (This is of course an oversimplification of their differences, but it is the difference that is causing problems.)

When / If the first patch (in the opening post) of the original issue of #1690130: Memcache fails to connect when using Unix sockets and PECL Memcached is reviewed or commented on, and someone of power is happy with the way I have done it there, or proposed a more suitable solution, I am willing to patch the memcache_admin module so that it can handle sockets and produce statistics for both PECL memcache and PECL memcached (provided I have a little time). Unfortunately #1690130: Memcache fails to connect when using Unix sockets and PECL Memcached has not been reviewed or commented on, so I do not know if what I have done is acceptable (I don't see why it would be unacceptable though).

With regards to this original post: As far as I remember this patch fixed the stats page only for PECL Memcache and not PECL Memcached as well, so marking as needs work. This is due to memcache defaulting to using PECL memcached over PECL memcache when both are available and one is not specifically set for use.

adammalone’s picture

So to clarify, this issue needs a patch that fixes memcache_admin stats page for both memcache and memcached?

Phizes’s picture

I believe so as this is currently on the project home page:

An API for using Memcached and the PECL Memcache or Memcached libraries with Drupal.

The module is supposed to support both of the PECL libraries, so I think socket support should be fixed for both of them.

rares’s picture

This issue still persists, at least in 6.x. The issues mentioned in #6 have all been closed. Can someone comment on whether this has been fixed in 7.x?

Phizes’s picture

With regards to #9, it has not been fixed as far as I am aware, at least not by me. (Un)fortunately I have been very busy with work for the past several months, and any patches I have written have been work related. As soon as I have time for recreational coding, I'll get onto this if someone else hasn't taken care of it already.

imclean’s picture

@typhonius, I don't think it supports memcached, which expects just the path to the socket without the protocol.

@rares, I've created a 6.x patch in another issue. Please see: #2085299: Support unix sockets with PECL memcached

imclean’s picture

Status: Needs work » Needs review
753 bytes

The issues mentioned in #6 have been resolved. This patch should fix the stats for both memcache and memcached extensions.

Jeremy’s picture

Issue summary: View changes
Status: Needs review » Fixed

This was close, but didn't quite work with the Memcached extension which apparently expects ":11211" instead of ":0". Fixed and committed:

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rodricels’s picture

Status: Closed (fixed) » Needs review

Are you sure about the expected :11211 port with Memcached?

I have a memcached working with a :0 port. With a :11211 port, the stats page don't work.


$conf['memcache_servers'] = array('unix:///var/run/memcached/memcached.sock' => 'default');

#12 patch works well

Jeremy’s picture

Have you tested with 7.x-1.1-beta4, without any patches applied?

If yes, a few questions:

  1. How did you start the memcache instance that's using the socket? (What exact CLI command did you type)?
  2. What version of the PECL mecached extension are you using?
  3. What OS / version is memcache running on?
rodricels’s picture

Yes, 7.x-1-1-beta4 without any patches.

debian 7.3
memcached debian package 1.4.13-0.2+deb7u1
PHP 5.4.24-1~dotdeb.1
pecl memcached 2.1.0 stable

memcached started with this config in service mode
cat /etc/memcached.conf
-m 128
-u nobody
# For memcached socket
-s /var/run/memcached/memcached.sock
-a 0766

Jeremy’s picture

Status: Needs review » Fixed

I reworked the admin stats overview to make the port irrelevant:

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.