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 :)
 
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:
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?
 
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.
 
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
 
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).
 
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/
 
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.
 
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';
 
I use this... is it wrong?
PHP:
$config['cache']['enabled'] = true;
$config['cache']['frontend'] = 'Core';
$config['cache']['frontendOptions'] = array(
    'caching'                  => true,
    'automatic_serialization'  => true,
    'lifetime'                  => 1800,
    'cache_id_prefix'          => 'xxx_xf'
);
#backend
#Memcached
$config['cache']['backend']='Memcached';
$config['cache']['backendOptions']=array(
      'compression'=>false,
      'servers' => array(
              array(
                  'host'=>'127.0.0.1',
                  'port'=>11211,
              )
        )
);
$config['cache']['cacheSessions'] = true;
 
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';
[/QUOTE]
what i put instead
memcached.hostname.com
 
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';

I tried using this (without the port) but it causes 500 errors on forum, thread pages.
 
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';
Works perfectly for me (I assume I'd get errors if not, lol)! Thanks!

Is there a way to confirm it is indeed running and working?
 
Top Bottom