简体   繁体   English

致命错误:在Zend Framework + Wamp中找不到类“ Memcache”

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

I have following code : 我有以下代码:

in application.ini application.ini中

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

in Bootstrap.php 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 而且我还通过将php_memcache.dll放在wamp\\bin\\php\\php5.3.9\\extextension=php_memcache.dll到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 (!)致命错误:在第160行的\\ wamp \\ www \\ projectname \\ application \\ Bootstrap.php中找不到类'Memcache'

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. 您要使用Zend_Cache。

(From: http://zendcoding.com/how-to-use-memcached-in-the-zend-framework ) (摘自: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; ?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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