简体   繁体   中英

Fatal error: Class 'Memcache' not found in Zend Framework + Wamp

I have following code :

in application.ini

cache.default.adapter = "memcached"
cache.default.params.host = "localhost"
cache.default.params.port = "11211"

in Bootstrap.php

$cache = new Memcache();        
$cache->connect($cache_params['host'], $cache_params['port']);
Zend_Registry::set("cache", $cache);

and also I am having memcache installed on my machine by putting php_memcache.dll in wamp\\bin\\php\\php5.3.9\\ext and also extension=php_memcache.dll in php.ini

But still I am getting the following error :

( ! ) Fatal error: Class 'Memcache' not found in \\wamp\\www\\projectname\\application\\Bootstrap.php on line 160

I have gone through google but still not able to solved the problem. What is the problem why it's not connecting to the memcache.

You are trying to cache your database?

You want to use Zend_Cache.

(From: http://zendcoding.com/how-to-use-memcached-in-the-zend-framework )

$frontendOpts = array(
    'caching' => true,
    'lifetime' => 1800, //how long in seconds to keep the cache for.
    'automatic_serialization' => true //In order to store objects and arrays, Zend must first serialize data into a string. If this parameter is set to ‘true‘, this serialization will happen on the fly and behind the scenes.
);

$backendOpts = array(
    'servers' =>array(
        array(
        'host'   => $cache_params['host'],
        'port'   => $cache_params['port'],
        'weight' => 1
        )
    ),
    'compression' => false
);

$cache = Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);

This link also demonstrates how to load and update the cache, and how to make it accessible from everywhere in your application. A good read, to be sure.

Your setting is memcached

cache.default.adapter = "memcached"

but you want to use memcache

$cache = new Memcache();

Try this example

 <?php $mc = new Memcached('mc'); $mc->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true); if (!count($mc->getServerList())) { $mc->addServers(array( array('127.0.0.1',11211), array('127.0.0.1',11211), )); } $key = 'mykey'; $mc->add($key,'test for memcached not memcache'); $val = $mc->get($key); echo $val; ?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM