Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The memcache extension must be loaded for using this backend

Tags:

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?

like image 667
Richard Knop Avatar asked Mar 20 '12 16:03

Richard Knop


2 Answers

PHP has two Memcached libraries with confusing names :

  • Memcache
  • Memcached (notice the d)

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.

like image 166
capi Avatar answered Oct 21 '22 10:10

capi


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

like image 39
john Avatar answered Oct 21 '22 08:10

john