Zendframework 2与memcache无法正常工作

时间:2015-10-14 16:09:47

标签: php zend-framework2 memcached

我正在尝试让memcache与Zendframework 2一起工作。如何让Zendframework 2看到memcache正确,所以我没有得到下面列出的错误?我想使用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

我验证了memcache服务已启动并正在运行 我验证了在Zendframework 2之外使用memecache。

接下来我按照本指南在Zendframework 2中使用它:How to setup Zendframework 2 to use Memcached我知道这个指南适用于memcached而不是memcache但我用它作为基础

我已经完成的故障排除:

  1. 已验证的服务正在运行
  2. 验证phpinfo()显示了memcache部分,所以我知道php扩展是从php.ini加载的
  3. 由于我在memcache vs memcached上仍然朦胧我尝试设置配置文件和上面的echo来尝试使用字符串 '分布式缓存'和' memcache'看看是否有助于找到它,但是 没有工作。
  4. 我在线阅读了一些关于“如何”的信息。事情可能与此冲突。我验证了我的配置没有加载任何' Di'
  5. 已验证抽象工厂设置已加载到Service Manager
  6. 下的配置中

    代码:

    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的自动加载目录中(取自上面的教程链接并删除了' 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
                ),
            ),
        ),
    ),
    

    );

1 个答案:

答案 0 :(得分:2)

您需要安装PHP库memcached,以便使用ZF Memcached Adapter。 ZF没有memcache库的适配器,所以它试图直接使用没有liboptions的setter的库。在配置中安装memcached或删除liboptions,您应该全部设置。