Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set memcached options in Yii2?

I'm trying to set a Memcached option (disable compression) in the config file, but Yii2 keeps throwing an error. What am I doing wrong?

Here is the config:

'cache' => [
    /* 'class' => 'yii\caching\FileCache', */
    'class' => 'yii\caching\MemCache',
    'servers' => [
        [
            'host' => 'localhost',
            'port' => 11211,
        ],
    ],
    'useMemcached' => true,
    'serializer' => false,
    'options' => [
        'Memcached::OPT_COMPRESSION' => false,
    ],
],

And the error: 'yii\base\ErrorException' with message 'Memcached::setOptions(): invalid configuration option'

Any ideas?

If I do the same thing in plain PHP, it works just fine:

$memcache = new \Memcached;
$memcache->setOption(\Memcached::OPT_COMPRESSION, false);
$memcache->addServers(
    array(
        array("HOST" => "127.0.0.1", "PORT" => 11211),
    )
);
like image 964
Littlebob Avatar asked Sep 10 '15 19:09

Littlebob


1 Answers

Try this

'options' => [
    \Memcached::OPT_COMPRESSION => false,
],
like image 135
Onedev_Link Avatar answered Oct 14 '22 10:10

Onedev_Link