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.

Comments

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.

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.

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

if you're using PECL Memcached should use patch in :http://drupal.org/node/1690130#comment-6323518

Status:Active» Needs review

The patch in #3 works for me.

Could this issue and http://drupal.org/node/1690130#comment-6323518 be merged?

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.

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

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.

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?

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.

@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

Status:Needs work» Needs review
StatusFileSize
new753 bytes

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

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:
http://drupalcode.org/project/memcache.git/commitdiff/b138d4a

Status:Fixed» Closed (fixed)

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

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.

Settings:

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

#12 patch works well

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?

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
-d
-m 128
-u nobody
# For memcached socket
-s /var/run/memcached/memcached.sock
-a 0766

Status:Needs review» Fixed

I reworked the admin stats overview to make the port irrelevant:
http://drupalcode.org/project/memcache.git/commitdiff/5211f36

Status:Fixed» Closed (fixed)

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