我安装了memcached。这是从phpinfo():
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9OVW5Jdy5wbmcifQ==” alt =“在此处输入图像描述”>
但是当这样使用时:
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;
}
我收到此错误:
The memcache extension must be loaded for using this backend
有什么想法吗?
对于您已安装的PHP库,看起来最简单的解决方案是使用不同的后端-如果您的zend框架版本允许,则使用它:
Zend_Cache_Backend_Libmemcached(http://doczf.mikaelkael.fr/1.11/en/zend.cache.backends.html)
我假设返回Zend_Cache :: factory('Core','Memcached',$ frontendOpts,$ backendOpts);变成return Zend_Cache :: factory('Core','Libmemcached',$ frontendOpts,$ backendOpts);
我解决这个问题很简单。发生此问题是因为您没有安装php memcached扩展名。让我们通过此命令在Ubuntu中安装它
sudo apt-get install php-memcached
或者在其他操作系统中您也可以自己弄清楚