The memcache extension must be loaded for using this backend
Asked Answered
N

4

21

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?

Niemeyer answered 20/3, 2012 at 16:23 Comment(3)
FYI ZF outputs that error if extension_loaded('memcache') returns false, so something weird is going on with your configuration.Zenda
Well, the problem seems to be that Zend_Cache_Backend_Memcached is loading memcache library instead of memcached. Why is it called mecached when it uses memcache? Wtf.Niemeyer
This might help: serverfault.com/questions/63383/memcache-vs-memcached - looking at my phpinfo, it's certainly 'memcache' that I have installed, whereas yours is listing 'memcached'Zenda
T
41

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.

Thebault answered 21/3, 2012 at 10:10 Comment(2)
Those names confuse me all the time. I never know whether I'm dealing with Memcache or Memcached or Libmemcached :PNiemeyer
xkcd.com/1742 would be great if you gave the full instructions. What do we add to the php.ini?Summon
P
2

for the PHP library that you have installed, it looks like the easiest solution would be to use a different backend - if your zend framework version allows it:

Zend_Cache_Backend_Libmemcached (http://doczf.mikaelkael.fr/1.11/en/zend.cache.backends.html)

i assume that return Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts); turns into return Zend_Cache::factory('Core', 'Libmemcached', $frontendOpts, $backendOpts);

Pittsburgh answered 21/8, 2013 at 18:9 Comment(0)
F
2

I solved this issue very easily. This issue happens because you didn't have the php 'memcached' extension installed. You can install it by using the following command in Ubuntu:

sudo apt-get install php-memcached

Also don't forget to restart the server after executing the above command

sudo /etc/init.d/apache2 restart

or

sudo service apache2 restart

or

sudo systemctl restart apache2

And for other OS, you can search for some alternative command.

Fealty answered 21/8, 2014 at 4:25 Comment(2)
E: Unable to locate package php-memcachedPosy
Simplier solution on Ubuntu based OS. Don't forget to restart server after $ sudo /etc/init.d/apache2 restartSweetie
V
2

needs extension called php-memcached possible solutions: (notice that extension is different from library, there are libraries called memcache & memchached, and extension called php-memcached. in my case the last one was needed) (on linux)

  • to install extension:
    sudo apt-get install php-memcached
    this will help you.

follow below if library is also needed.

  • to install library itself: sudo apt-get install memcached
  • there is also a library containing memcached: sudo apt-get install libmemcached-tools

to read more and configure it you may want to check here and here

Vaudeville answered 13/1, 2020 at 10:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.