gpt4 book ai didi

php - 如何在命名空间应用程序中使用内存缓存?

转载 作者:行者123 更新时间:2023-12-04 16:59:22 28 4
gpt4 key购买 nike

我想在我的应用程序中使用 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;

但我不知道如何在 中为 Memcache 创建对象Zend 框架 2 对于普通 Memcache,当我尝试将错误显示为:
Fatal error: Class 'Application\Controller\Memcache' not found

请帮我解决我的问题。

最佳答案

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

$memcache = new \Memcache;

关于php - 如何在命名空间应用程序中使用内存缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22709033/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com