zoukankan      html  css  js  c++  java
  • PHP处理大数据量老用户头像更新的操作--解决数据量大超时的问题

        /**
         * @title 老用户头像更新--每3秒调用一次接口,每次更新10条数据
         * @example user/createHeadPicForOldUser?
         * @method GET
         * @author 邹柯
         */
        public function createHeadPicForOldUserAction(){
            $domain=$_SERVER['HTTP_HOST'];
            $ob = new UserModel();
            $user=M('user');
            $u_where="head_pic is null or head_pic=''";
            $count=$user->where($u_where)->count();
            $user_info=$user->field('user_id')->where($u_where)->page(1,10)->select();
            if($count !=0){
                for($i=0;$i<10;$i++){
                    //获取一个默认头像
                    $h_pic=$ob->getDefaultUserHeadPic();
                    $re=$user->data(['head_pic'=>$h_pic])->where(['user_id'=>$user_info[$i]['user_id']])->save();
                }
                echo "还剩".$count."条记录没更新";
                exit("<script>setTimeout(function(){location.href='http://$domain/user/createHeadPicForOldUser';},3000);</script>");
            }else{
                exit("更新完毕");
            }        
            
        }
        //注册时给用户分配一个随机头像(或老用户登录时给其分配一个随机头像)
        public function getDefaultUserHeadPic(){
            $default_avatar=M('default_avatar a');
            $avatar_style=M('avatar_style s');
            $da_where['a.is_deleted']=0;
            $da_where['a.status']=1;
            $da_where['s.is_deleted']=0;
            $da_where['s.status']=1;
            $default_avatar_info=$default_avatar->field("a.id,img as head_pic")
                    ->join('left join lc_avatar_style s on a.style_id=s.id')
                    ->where($da_where)
                    ->select();  
            $cn=count($default_avatar_info);
            $cs=rand(0,$cn-1);
            return $default_avatar_info[$cs]['head_pic'];
        }    
  • 相关阅读:
    hdu 5025 bfs+状压
    hibernate的saveOrUpdate方法
    jsp中使用css选择器与<c:foreach>标签的问题
    5- js 正则的方法
    cookie存储的值
    word中目录的灰色是怎么回事?
    css三角形
    windows下,OracleServiceXXX和Oracle 实例的关系
    echo的功能
    myeclipse 删除不再使用的工作空间记录
  • 原文地址:https://www.cnblogs.com/zouke1220/p/9096507.html
Copyright © 2011-2022 走看看