The memcache extension must be loaded for using this backend

Richard Knop picture Richard Knop · Mar 20, 2012 · Viewed 32.4k times · Source

I got memcached installed. This is from phpinfo():

enter image description here

But when using it like this:

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;
}

I get this error:

The memcache extension must be loaded for using this backend

Any ideas?

Answer

capi picture capi · Mar 21, 2012

PHP has two Memcached libraries with confusing names :

Your code needs the first one. Just do a simple pecl uninstall memcached and then pecl install memcache, modify your php.ini to include the appropiate .so and it should work.