【问题标题】:Memcached setup with cakephp3使用 cakephp3 设置 Memcached
【发布时间】:2015-08-01 14:22:51
【问题描述】:

我正在使用 cakephp3 设置 memcache 设置。我在config/app.php下面添加了

'Cache' => [
   'default' => [
        'className' => 'Cake\Cache\Engine\MemcachedEngine',            
    ],
]

在我添加的控制器顶部 使用蛋糕\缓存\缓存; 使用蛋糕\缓存\缓存引擎; 使用 Cake\Cache\CacheRegistry;

但是当我使用内存缓存的任何功能时,例如 Cache::write('variable','value'); ETC 它给了我错误 " 错误:缓存引擎 Cake\Cache\Engine\MemcachedEngine 配置不正确。"

memcached 已安装在服务器上。这是输出

/etc/php.d/memcache.ini,
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 32768 => 32768
memcache.compress_threshold => 20000 => 20000
memcache.default_port => 11211 => 11211
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => consistent => consistent
memcache.lock_timeout => 15 => 15
memcache.max_failover_attempts => 20 => 20
memcache.protocol => ascii => ascii
memcache.redundancy => 1 => 1
memcache.session_redundancy => 2 => 2

请告诉我配置中剩余的内容。提前致谢。

【问题讨论】:

    标签: cakephp memcached cakephp-3.0


    【解决方案1】:

    错误的扩展名

    与memcache相关的php扩展有两个:

    CakePHP Memcached 驱动程序relies on memcacheD:

    if (!extension_loaded('memcached')) {
        return false;
    }
    

    如果没有哪个will result in that error message

    if (!$instance->init($config)) {
        throw new RuntimeException(
            sprintf('Cache engine %s is not properly configured.', get_class($instance))
        );
    }
    

    【讨论】:

    • 感谢您的回复。我还需要在配置文件中添加其他内容吗?我已经在app.php中写了上面的内容。对吗?
    • 我已经安装了 memcached,但它仍然无法正常工作。是否还有其他配置需要在配置中添加/删除。
    • 在 phpinfo.. session.save_handler 文件 memcached 中。在命令行上,我尝试了 [root@server ~]# memcached-tool 127.0.0.1 stats #127.0.0.1:11211 Field Valueaccepting_conns 1 auth_cmds 0 auth_errors 0 bytes 0 bytes_read 14 和更多行。在 app.php 中我使用了相同的如上。但是引擎 Cake\Cache\Engine\MemcachedEngine 配置不正确。
    • 确定为什么 the init method 返回 false - 我不能/不会猜测为什么您的安装不起作用。上述评论并未向我确认已安装 memcached 扩展。
    • 它现在可以工作了。实际上我们需要同时安装 memcache 和 memcached 才能正常工作。 memcached 是一个恶魔,但 memcache 需要 php。谢谢
    猜你喜欢
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-07
    • 2012-12-03
    • 2022-08-18
    • 2011-03-28
    相关资源
    最近更新 更多