![](/img/trans.png)
[英]Memcache & php: Fatal error: Class 'Memcache' not found in
[英]Fatal error: Class 'Memcache' not found in Zend Framework + Wamp
我有以下代码:
在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);
而且我还通过将php_memcache.dll
放在wamp\\bin\\php\\php5.3.9\\ext
和extension=php_memcache.dll
到php.ini中的机器上安装了内存缓存
但仍然出现以下错误:
(!)致命错误:在第160行的\\ wamp \\ www \\ projectname \\ application \\ Bootstrap.php中找不到类'Memcache'
我已经通过谷歌,但仍然无法解决问题。 为什么它不连接到内存缓存是什么问题。
您要缓存数据库吗?
您要使用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);
此链接还演示了如何加载和更新缓存,以及如何从应用程序的任何位置访问它。 一定要读一读。
您的设置是内存缓存
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; ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.