簡體   English   中英

致命錯誤:在Zend Framework + Wamp中找不到類“ Memcache”

[英]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\\extextension=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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM