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

时间:2012-10-17 09:44:01

标签: php zend-framework memcached

我有以下代码:

application.ini

中的

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

中的

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

并且我在我的机器上安装了memcache,将php_memcache.dll放在wamp\bin\php\php5.3.9\ext中,并将extension=php_memcache.dll放在php.ini中

但我仍然收到以下错误:

(!)致命错误:第160行\ wamp \ www \ projectname \ application \ Bootstrap.php中找不到类'Memcache'

我已经通过谷歌,但仍然无法解决问题。为什么它没有连接到memcache会有什么问题。

2 个答案:

答案 0 :(得分:1)

您正在尝试缓存数据库?

您想使用Zend_Cache。

(来自: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);

此链接还演示了如何加载和更新缓存,以及如何从应用程序的任何位置访问缓存。一定要好好阅读。

答案 1 :(得分:0)

您的设置是memcached

cache.default.adapter = "memcached"

但你想使用memcache

$cache = new Memcache();

试试这个例子



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


?>
&#13;
&#13;
&#13;