【问题标题】:Php Memcache Error Case and handlingPhp Memcache错误案例及处理
【发布时间】:2019-01-08 01:01:58
【问题描述】:

我将每个客户评论的前 50 条评论存储在 memcache 中。我想知道我会遇到哪种错误以及如何处理该错误。 我正在使用此代码:

$memcache = new Memcache();
$memcache->connect('127.0.0.1', 11212);
//Key to get user total from cache
$user_total     = md5("user_total_".$user);        
//Get User total from cache
$get_user_total = $memcache->get($user_total);
$total_reviews  = 0;

if($get_user_total){
    $total_reviews = !empty($get_user_total) ? $get_user_total : 0;
}else{

    $sql = " SELECT  COUNT(*) as total FROM user AS u ";
    $sql.= " JOIN onj_ship_awb AS sa ON(u.user_id = sa.user_id) ";
    $sql.= " JOIN onj_customer_feedback AS cf  ON (cf.ship_awb_id = sa.id) ";
    $sql.= " WHERE u.username = '' AND u.password = ''  AND cf.status = '1' AND cf.insert_time  <= ( CURDATE() - INTERVAL 3 DAY ) ";
    $result = $con->query( $sql );
    $total_reviews  = $result->fetch_assoc();
    $total_reviews  = $total_reviews['total'];
    $memcache->set($user_total,$total_reviews,MEMCACHE_COMPRESSED,TTL);
    $total_reviews = !empty($total_reviews) ? $total_reviews : 0;
}  

例如,如果我连接到 11211 以外的端口,则会抛出错误。

Memcache::connect(): 服务器 127.0.0.1 (tcp 11212, udp 0) 失败:连接被拒绝 (111)

那么我该如何处理这种错误以及我应该处理哪些其他情况?

【问题讨论】:

    标签: php memcached


    【解决方案1】:

    这就是我们检查 Memcache 连接状态的方法。

    $memcache = new Memcache();
    $memcache_status = @$memcache->connect('127.0.0.1', 11212);
    if($memcache_status){
        //Success
    }else{
        //Fail
    }
    

    【讨论】:

    • @感谢您的解决方案
    猜你喜欢
    • 2011-10-15
    • 2011-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2011-06-27
    相关资源
    最近更新 更多