2012-10-17 64 views
0

我有以下代碼:致命錯誤:類 '內存緩存' Zend框架+未發現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); 

而且我還在我的機器上安裝了memcache,將php_memcache.dll放入在php.ini,也extension=php_memcache.dll

不過還是我收到以下錯誤:

(! )致命錯誤:無法在\ wamp \ www \ projectname \ application \ Bootstrap.php上找到類'Memcache'on line 160

我已經通過谷歌,但仍然無法解決問題。有什麼問題沒有連接到內存緩存。

+0

如果你設置了'phpinfo()'頁面,那麼這裏列出的是Memcache擴展名? –

+0

@Tim Fountain:不,沒有列出memcache擴展 – Sky

回答

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

此鏈接還演示瞭如何加載和更新緩存,以及如何使來自世界各地的在你的應用程序訪問。可以肯定,閱讀很好。

+0

其實我把我的操作系統從ubuntu移到了windows。在Ubuntu中,它工作完美,但爲什麼它在Windows中顯示問題。我通過引用此鏈接在Windows中安裝了memcache:http://www.codeforest.net/how-to-install-memcached-on-windows-machine – Sky

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; 
 

 

 
?>

相關問題