XF 2.0 config.php memcached

MattW

Well-known member
#1
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
#2
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:
#3
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
#4
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.
 
#6
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
 
#8
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).
 
#9
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
#12
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
#13
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