【问题标题】:How to use memcache in a namespaced application?如何在命名空间应用程序中使用内存缓存?
【发布时间】:2014-03-28 09:40:38
【问题描述】:

我想在我的应用程序中使用 memcache。我在 php.ini 文件中启用了 php_memcache.dll 并且正常的 memcache 在简单的 PHP 中工作正常

$memcache = new Memcache;
$memcache->connect('localhost', 11211);
$test = $memcache->get("A");
if(empty($test)){
       echo "setting cache";
       $memcache->set("A","Cache contents",MEMCACHE_COMPRESSED,50);
}
echo $test;

但是当我试图将错误显示为:

Fatal error: Class 'Application\Controller\Memcache' not found

请帮我解决我的问题。

【问题讨论】:

    标签: php namespaces


    【解决方案1】:

    您似乎正在尝试从您的控制器初始化 Memcache 对象,该控制器位于 Application\Controller 命名空间中。在这种情况下,它会在同一命名空间中查找 Memcache。您需要从全局命名空间中将其引用为:

    $memcache = new \Memcache;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-21
      • 2018-12-26
      • 2013-04-04
      • 1970-01-01
      • 2016-06-03
      • 2015-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多