必须加载memcache扩展才能使用此后端

Ric*_*nop 19 php memcached zend-framework

我安装了memcached.这是来自phpinfo():

在此输入图像描述

但是当它像这样使用时:

private static function getZendCacheMemcachedObject()
{
    $frontendOpts = array(
        'caching' => true,
        'lifetime' => 3600,
        'automatic_serialization' => true
    );

    $backendOpts = array(
        'servers' =>array(
            array(
            'host'   => 'localhost',
            'port'   => 11211,
            'weight' => 1
            )
        ),
        'compression' => false
    );

    return Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);
}

public function foo($id)
{
    $cache = self::getZendCacheMemcachedObject();
    $cacheKey = 'foo_'.$id;
    $xml = $cache->load($cacheKey);

    if (false === $xml) {
        $xml = $this->httpClient->foo();
        $cache->save($xml, $cacheKey);
    }

    return $xml;
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

The memcache extension must be loaded for using this backend
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

小智 39

PHP有两个Memcached库,名称令人困惑:

您的代码需要第一个.只是做一个简单的pecl uninstall memcached,然后pecl install memcache,修改你php.ini的包括适当的.so它应该工作.

  • 如果您提供完整说明,https://xkcd.com/1742/ 会很棒。我们在 php.ini 中添加什么? (2认同)