XF 2.0 config.php memcached

MattW

Well-known member
Apologies if I've missed something really obvious, but what are the settings that are needed for config.php in XF2 to enable Memcached as the back end cache?

I've tried searching, but only Redis comes up in the results.

Thanks :)
 

Chris D

XenForo developer
Staff member
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'servers' => [
        ['memcached.hostname.com', 11211, 33] // host, port, weight
        // more servers
    ]
];
$config['cache']['provider'] = 'Memcached';
If it's just a single server with default port and weight etc:
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'server' => 'memcached.hostname.com'
];
$config['cache']['provider'] = 'Memcached';
 
Last edited:

webmastersun

Active member
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'servers' => [
        ['memcached.hostname.com', 11211, 33] // host, port, weight
        // more servers
    ]
];
$config['cache']['provider'] = 'Memcached';
If it's just a single server with default port and weight etc:
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'server' => 'memcached.hostname.com'
];
$config['cache']['provider'] = 'Memcached';
What are configs to use multi forums on a same server with Memcached?
 

Chris D

XenForo developer
Staff member
As far as I know the only way to separate memcached instances is to physically run separate instances on different ports, so you'd just use this approach:
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'servers' => [
        ['memcached.hostname.com', 11212]
    ]
];
$config['cache']['provider'] = 'Memcached';
So one forum would use port 11211. Another would use 11212 etc.
 

webmastersun

Active member
As far as I know the only way to separate memcached instances is to physically run separate instances on different ports, so you'd just use this approach:
PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'servers' => [
        ['memcached.hostname.com', 11212]
    ]
];
$config['cache']['provider'] = 'Memcached';
So one forum would use port 11211. Another would use 11212 etc.
Memcached is listening on one port 11211, that requires to config memcached with multi ports?
I thought we need to have a prefix in this case like on another forum software that integrated with Memcached
 

webmastersun

Active member
I think he just means different prefixes for different forums:
Code:
$config['cache']['namespace'] = 'your_prefix';
Whoops, you posted this reply while I am typing the previous reply :D
It is a better way instead of using multi ports.
Thanks
 

Tipmoose

Member
Im trying to implement caching of my forum on a CentOS system using memcache. Since this thread contains almost all of the information I need, I figured I'd resurrect it instead of posting a new one. I hope that's ok.

First question: Do I need to install both memcache and the php extension for memcache to use this?
Second question: Is "memcached.hostname.com" just the domain on which I've installed memcache? (mydomain.com).
 

BobbyUgh

Member
First question: Do I need to install both memcache and the php extension for memcache to use this?
Second question: Is "memcached.hostname.com" just the domain on which I've installed memcache? (mydomain.com).
Yes you need both, and memcached.hostname.com you can just substitute for the ip of where its hosted.

Please make sure you disable UDP and protect the memcached server outside connections: https://blog.cloudflare.com/memcrashed-major-amplification-attacks-from-port-11211/
 

Anthony Parsons

Well-known member
Re single server above:

PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['config'] = [
    'server' => 'memcached.hostname.com'
];
$config['cache']['provider'] = 'Memcached';
Is this still applicable vs the help documents?

PHP:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];
So... if converting over this type of front and back XF1 to XF2:

PHP:
$config['cache']['enabled'] = true;
$config['cache']['cacheSessions'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
'caching' => true,
'cache_id_prefix' => 'xfxx_',
'automatic_serialization' => false,
'lifetime' => 0
);

$config['cache']['backend'] = 'Libmemcached';

$config['cache']['backendOptions'] = array(
'servers' => array(
array(
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 1
)
)
);
I assume frontend cache is no more, and just the memcache would be:

PHP:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['namespace'] = 'xfxx_';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];
Is sessions a requirement still? Is the prefix format correct?

Running on centminmod.
 

MattW

Well-known member
This is what I'm running, and have been since converting to XF2

PHP:
$config['cache']['enabled'] = true;
$config['cache']['sessions'] = true;
$config['cache']['namespace'] = 'XXX_';
$config['cache']['config'] = [
    'servers' => [
        ['localhost', 11211]
    ]
];
$config['cache']['provider'] = 'Memcached';
 
Top