0

我有以下代码:

应用程序.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);

而且我通过在 php.ini和php.iniphp_memcache.dll中安装了 memcachewamp\bin\php\php5.3.9\extextension=php_memcache.dll

但我仍然收到以下错误:

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

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

4

2 回答 2

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

此链接还演示了如何加载和更新缓存,以及如何从应用程序中的任何位置访问它。可以肯定的是,这是一本好书。

于 2012-10-17T09:58:00.010 回答
0

您的设置是 memcached

cache.default.adapter = "memcached"

但你想使用内存缓存

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


?>

于 2015-07-09T19:12:59.273 回答