zoukankan      html  css  js  c++  java
  • YII实现Memcache故障转移的配置办法

    YII在默认配置下连接Memcache失败时会报错,要想实现故障转移就要改一下配置和代码

    1、首先修改一下YII的 caching/CMemCache.php,我的版本是 1.1.7

    找到 

    $cache->addServer($server->host,$server->port,$server->persistent,$server->weight,$server->timeout,$server->status);

    改为

    $cache->addServer(
      $server->host,
      $server->port,
      $server->persistent,
      $server->weight,
      $server->timeout,
      $server->retryInterval,
      $server->status);

    原因:源码中少了 retryInterval 参数,这是故障转移的关键参数

    retry_interval 的官方解释

    服务器连接失败时重试的间隔时间,默认值15秒。如果此参数设置为-1表示不重试。

    FROM http://php.net/manual/zh/memcache.addserver.php

    2、修改YII应用的配置文件 protected/config/main.php 中的cache配置项

    'cache'=>array(
                'class'=>'system.caching.CMemCache',
                //'useMemcached'=> true,
                'servers'=>array(
                     array(
                         'host'=>'127.0.0.1',
                         'port'=>11211,
                         'weight'=>40,
                         'timeout' => 5,
                         'retryInterval' => -1
                     ),
                    array(
                         'host'=>'127.0.0.1',
                         'port'=>11212,
                         'weight'=>30,
                         'timeout' => 5,
                         'retryInterval' => -1
                     ),
                    array(
                         'host'=>'127.0.0.1',
                         'port'=>11213,
                         'weight'=>50,
                         'timeout' => 5,
                         'retryInterval' => -1
                     ),
                ),
             ),

    以上代码中只有一个是能正确使用的MC服务器,即端口是11211的服务器是正常开启的

    如此配置也能正常运行了

  • 相关阅读:
    Mobile phones(poj1195)
    Matrix(poj2155)
    1080
    1266
    codeforces626D . Jerry's Protest
    字符串格式化
    附加MySQL数据库的方法
    avaScript中变量的声明和赋值
    选择法排序
    JavaScript中变量的类型
  • 原文地址:https://www.cnblogs.com/imbin/p/3861039.html
Copyright © 2011-2022 走看看