带有内存缓存的 Zendframework 2 不工作

Zendframework 2 with memcache not working

我正在尝试让内存缓存与 Zendframework 2 一起工作。如何让 Zendframework 2 看到内存缓存正确,这样我就不会收到下面列出的错误?我想使用 memcache 而不是 memcached。

错误

Exception - An abstract factory could not create an instance of memcache(alias: memcache).

Previous exceptions - An exception was raised while creating "memcache"; no instance returned

The option "liboptions" does not have a matching setLiboptions setter method which must be defined

当我试图在控制器中使用这一行进行测试时出现此错误

echo $this->getServiceLocator()->get('memcache')->getVersion();

详情:

我是 运行 windows 7 64 位,具有 IIS7 的本地实例并且 运行。

我使用本指南在我的电脑上安装了 memecache:How to Install Memcache on Windows 7

我验证了内存缓存服务已启动并且 运行 我验证了在 Zendframework 2 之外使用 memecache 是有效的。

所以接下来我按照本指南使其在 Zendframework 2 中工作:How to setup Zendframework 2 to use Memcached我知道本指南适用于 memcached 而不是 memcache 但我将其用作基础

我已经完成的故障排除:

  1. 已验证的服务是 运行
  2. 已验证 phpinfo() 显示内存缓存部分,因此我知道 php 扩展正在从 php.ini
  3. 加载
  4. 因为我对 memcache 和 memcached 还是一头雾水,所以我尝试设置配置文件和上面的 echo 来尝试使用字符串 'memcached' 和 'memcache' 看看这是否有助于找到它,但是 没用。
  5. 我在网上阅读了一些有关 'Di' 的内容如何与此冲突的内容。我验证了我的配置没有使用 'Di'
  6. 加载任何内容
  7. 已验证抽象工厂设置已加载到服务管理器下的配置中

代码:

config var_dump 显示抽象工厂部分正在加载

$sm = $this->getServiceLocator();
$config = $sm->get('config');
var_dump($config);die();

'service_manager' => 
array (size=3)
  'abstract_factories' => 
    array (size=2)
      0 => string 'Zend\Cache\Service\StorageCacheAbstractServiceFactory' (length=53)
      1 => string 'Zend\Log\LoggerAbstractServiceFactory' (length=37)
  'aliases' => 
    array (size=2)
      'translator' => string 'MvcTranslator' (length=13)
      'db' => string 'Zend\Db\Adapter\Adapter' (length=23)
  'factories' => 
    array (size=1)
      'Zend\Db\Adapter\Adapter' => string 'Zend\Db\Adapter\AdapterServiceFactory' (length=37)

我的 cache.local.php 它在 zendframework 2 的自动加载目录中(取自上面的教程 link 并删除了 'd') 我认为这是我需要更改的,只是不确定如何更改....

return array(
'caches' => array(
    'memcache' => array( //can be called directly via SM in the name of 'memcache'
        'adapter' => array(
            'name'     =>'memcache',
            'lifetime' => 86400,    //24 hours
            'options'  => array(
                'servers'   => array(
                    array(
                        '127.0.0.1',11211   //Server IP, Port
                    )
                ),
                'namespace'  => 'MYMEMCACHENAMESPACE',
                'liboptions' => array (
                    'COMPRESSION' => true,
                    'binary_protocol' => true,
                    'no_block' => true,
                    'connect_timeout' => 120
                )
            )
        ),
        'plugins' => array(
            'exception_handler' => array(
                'throw_exceptions' => false
            ),
        ),
    ),
),

);

您需要安装 PHP 库 memcached so you can use ZFs Memcached Adaptor. ZF does not have an adaptor for the memcache 库,以便它尝试直接使用 liboptions 没有 setter 的库。在您的配置中安装 memcached 或删除 liboptions,您应该已经准备就绪。