php 必须加载 memcache 扩展才能使用此后端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9790780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The memcache extension must be loaded for using this backend
提问by Richard Knop
I got memcached installed. This is from phpinfo():
我安装了 memcached。这是来自 phpinfo():
But when using it like this:
但是当像这样使用它时:
private static function getZendCacheMemcachedObject()
{
$frontendOpts = array(
'caching' => true,
'lifetime' => 3600,
'automatic_serialization' => true
);
$backendOpts = array(
'servers' =>array(
array(
'host' => 'localhost',
'port' => 11211,
'weight' => 1
)
),
'compression' => false
);
return Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts);
}
public function foo($id)
{
$cache = self::getZendCacheMemcachedObject();
$cacheKey = 'foo_'.$id;
$xml = $cache->load($cacheKey);
if (false === $xml) {
$xml = $this->httpClient->foo();
$cache->save($xml, $cacheKey);
}
return $xml;
}
I get this error:
我收到此错误:
The memcache extension must be loaded for using this backend
Any ideas?
有任何想法吗?
回答by capi
PHP has two Memcached libraries with confusing names :
PHP 有两个具有混淆名称的 Memcached 库:
Your code needs the first one. Just do a simple pecl uninstall memcached
and then pecl install memcache
, modify your php.ini
to include the appropiate .so and it should work.
您的代码需要第一个。只需做一个简单的pecl uninstall memcached
然后pecl install memcache
,修改您的php.ini
以包含适当的 .so,它应该可以工作。
回答by john
for the PHP library that you have installed, it looks like the easiest solution would be to use a different backend - if your zend framework version allows it:
对于您已安装的 PHP 库,看起来最简单的解决方案是使用不同的后端 - 如果您的 zend 框架版本允许:
Zend_Cache_Backend_Libmemcached (http://doczf.mikaelkael.fr/1.11/en/zend.cache.backends.html)
Zend_Cache_Backend_Libmemcached ( http://doczf.mikaelkael.fr/1.11/en/zend.cache.backends.html)
i assume that return Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts); turns into return Zend_Cache::factory('Core', 'Libmemcached', $frontendOpts, $backendOpts);
我假设 return Zend_Cache::factory('Core', 'Memcached', $frontendOpts, $backendOpts); 变成 return Zend_Cache::factory('Core', 'Libmemcached', $frontendOpts, $backendOpts);
回答by Phuc
I solve this issue is quite simple. This issue happen because you didn't install php memcached extension. Let 's install it by this command in Ubuntu
我解决这个问题很简单。发生此问题是因为您没有安装 php memcached 扩展。让我们在 Ubuntu 中通过这个命令安装它
sudo apt-get install php-memcached
Or in other OS you can figure out yourself
或者在其他操作系统中,您可以自己弄清楚
回答by ToTo
needs extension called php-memcached
possible solutions:
(notice that extension is different from library, there are libraries called memcache
& memchached
, and extension called php-memcached
. in my case the last one was needed)
(on linux)
需要扩展名为 php-memcached 可能的解决方案:(注意扩展与库不同,有名为memcache
& 的库memchached
和名为php-memcached
. 的扩展。在我的情况下需要最后一个)(在 linux 上)
- to install extension:
sudo apt-get install php-memcached
this will help you.
- 安装扩展:
sudo apt-get install php-memcached
这会帮助你。
follow below if library is also needed.
如果还需要库,请按照以下步骤操作。
- to install library itself:
sudo apt-get install memcached
- there is also a library containing memcached:
sudo apt-get install libmemcached-tools
- 安装库本身:
sudo apt-get install memcached
- 还有一个包含 memcached 的库:
sudo apt-get install libmemcached-tools
to read more and configure it you may want to check hereand here