将yii与memcache结合使用,当两个服务器之一发生故障时出错 [英] using yii with memcache, error when one of two server fails
问题描述
我对ii和将数据存储在内存缓存中有问题.对于我的应用程序,我使用system.caching.CMemCache和以下配置:
i have a problem with yii and storing data in memcache. For my application i use system.caching.CMemCache and the following config:
'servers' => array(
'server1' => array('host' => 'localhost', 'port' => 11211, 'weight' => 50),
'server2' => array('host' => '192.168.0.2', 'port' => 11211, 'weight' => 50)
),
如果两个系统上的内存缓存都在运行,则一切正常,并且这些值将散布在服务器上.但是,如果一台服务器发生故障(或者如果我手动停止了内存缓存),则该应用程序会抛出诸如
if memcache on both systems is running, everything is ok and the values get spread up on the servers. but if one server fails (or if i stop the memcache manually) the application throw errors like
MemcachePool::get(): Server 192.168.0.2 (tcp 11211, udp 0) failed with: Connection refused (111)
这不是很好,我想如果一台服务器出现故障,yii会选择另一台服务器进行读写,或者至少会产生一些高速缓存未命中,并且不会抛出异常:(
this isn't really nice, i thought if one server failed yii would choose another server for reading and writing or at least produce some cache misses and do not throw an exeption :(
这是正常现象还是存在一些配置问题?
is this normal or are there some configuration issues?
推荐答案
I think its normal you are seeing those messages as discussed here, given you are using memcache
extension
还要阅读 SO .
php扩展有两个版本,一个是memcache
,另一个是memcached
.您可以将它们安装在ubuntu盒子上,例如:
There are two version of extension for php one is memcache
while the other is memcached
. You can install each of them on ubuntu box like :
sudo apt-get install php5-memcache
and
sudo apt-get install php5-memcached
Memecached
扩展程序处理failover
情况,正如我从上述链接中读取的内容并通过测试yii中的以下设置进行确认
Memecached
extension handles failover
situations ,as I read from the above links and confirm by testing following settings in yii
'cache'=>array(
'class'=>'CMemCache',
'useMemcached'=>true,
'servers'=>array(
array(
'host'=>'localhost',
'port'=>11211,
'weight'=>60,
),
array(
'host'=>'192.168.33.31',
'port'=>11211,
'weight'=>30,
),
),
),
如上所述安装php的memcached
扩展名并添加'useMemcached'=>true,
设置以缓存配置.当我在本地主机上进行测试时,它可以处理故障转移情况,但是页面响应时间大大缩短.
Install the memcached
extension for php as described above and add 'useMemcached'=>true,
setting to cache configs.As I test on my localhost, it handles the failover situation, but the page response time drops significantly.
希望这会有所帮助.
这篇关于将yii与memcache结合使用,当两个服务器之一发生故障时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!