【问题标题】:Fatal error: Class 'Memcache' not found in Zend Framework + Wamp致命错误:在 Zend Framework + Wamp 中找不到类“Memcache”
【发布时间】:2012-10-07 13:01:30
【问题描述】:

我有以下代码:

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 中,在我的机器上安装了memcache

但我仍然收到以下错误:

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

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

【问题讨论】:

  • 如果你设置了一个phpinfo() 页面,Memcache 扩展是否列在那里?
  • @Tim Fountain :不,没有列出内存缓存扩展

标签: php zend-framework memcached


【解决方案1】:

你的设置是内存缓存

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;


?>

【讨论】:

    【解决方案2】:

    您正在尝试缓存您的数据库?

    你想使用 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);
    

    此链接还演示了如何加载和更新缓存,以及如何从应用程序的任何位置访问它。不错的读物,这是肯定的。

    【讨论】:

    猜你喜欢
    • 2011-11-05
    • 2011-06-27
    • 1970-01-01
    • 2010-12-26
    • 2011-02-09
    • 2011-11-08
    • 2015-04-22
    相关资源
    最近更新 更多