Memcached with a socket

nodle

Well-known member
Can someone tell me which is the correct way to use memcached with a socket?

Is it:
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];

Or:
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => 'unix:///home/mysite/.applicationmanager/memcached.sock:0'
];

My socket is located at:

/home/mysite/.applicationmanager/memcached.sock

Or is there something else that I should be using instead? Thanks. :)
 
The first one will use TCP. The second one looks more correct for the socket but I'm not sure what the ":0" bit you have on the end there is for. It should just be the path to the socket and nothing else. It looks as if you're trying to define a blank port number or something.

EDIT - PS, it sounds like you're on the right track anyway but sockets will be slightly faster than local TCP :)
 
The first one will use TCP. The second one looks more correct for the socket but I'm not sure what the ":0" bit you have on the end there is for. It should just be the path to the socket and nothing else. It looks as if you're trying to define a blank port number or something.

EDIT - PS, it sounds like you're on the right track anyway but sockets will be slightly faster than local TCP :)
Thanks for the help @JonathanW . I just never seem to get a straight answer on it. I ran into this same thing when I was on IPS. Even the support at IPS never seemed to have the correct answer. Is there an official answer for Xenforo? @Chris D?
 
I believe Xenforo uses the Memcached extension - http://php.net/manual/en/memcached.addserver.php
The hostname of the memcache server. If the hostname is invalid, data-related operations will set Memcached::RES_HOST_LOOKUP_FAILURE result code. As of version 2.0.0b1, this parameter may also specify the path of a unix socket filepath ex. /path/to/memcached.sock to use UNIX domain sockets, in this case port must also be set to 0.

Xenforo's documentation doesn't show how to specify a port for Memcached, however looking at the code this should work:
PHP:
$config['cache']['config'] = [
    'servers' => [
        ['/home/mysite/.applicationmanager/memcached.sock', 0]
    ]
];
 
Thanks for the help @Sam9 , if I add your way or the default '127.0.0.1' both seem to work. My problem is I can't tell which one is the proper method. I can't see if it's actually caching anything or not. That is why it would be nice to have an official answer from Xenforo on this and maybe document it under their Xenforo Help Manual so other's would know as well. @Mike @Chris D .
 
@nodle if you put a bad config there your site will break, so if it's working then it means that XF is talking to Memcached if you have caching set to true.

I'm recently starting to become a fan of Redis. If you were to swap over to that they have a quick and easy command to spit out caching stats: "redis-cli info"
 
I was using Redis before switching back to Memcached. Redis started throwing errors at me. Problem is my Redis is run off a socket as well. I know Redis is suppose to be better in certain situations, but honestly I can't tell a difference between it and Memcached.
 
Back
Top Bottom