账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    lnmp高并发情况下出现TP5中的函数重复执行
    77
    0

    1.

    问题描述

    lnmp高并发情况下出现TP5中的函数重复执行

    问题出现的环境背景及自己尝试过哪些方法

    已经使用cache作为判断标准,限制一段时间内就算函数执行,也保证数据不会入库。

    相关代码

    php代码:

     public function winprize()
    {
        if (Request::instance()->isPost()){
            $openid=Cookie::get('hzz_openid');
            $win_type=db('winprize')->where('openid',$openid)->where('state',0)->field('type')->find();
            if($win_type){
                if($win_type['type']==0){
                    return json(['code'=>4,'msg'=>'存在记录']);
                }else{
                    return json(['code'=>5,'msg'=>'不存在的记录']);
                }
            }
            $user_id=input('id');
            $user=db('user')->where('id',$user_id)->find();
            if($user['number']<$user['max_number']){
                if($user['max_number']>2){
                    $fact_assist=db('assist')->where('openid_ass',$openid)->count();
                    if($fact_assist<(5*$user['max_number'])){
                  db('assist')->where('openid_ass',$openid)->update(['max_number'=>floor($fact_assist/5)]);
                        return json(['code'=>2,'msg'=>'无效的']);
                    }
                }
                $jackpot=db('jackpot')->where('state',1)->find();
                $data['jackpot_id']=$jackpot['id'];
                $data['user_id']=$user['id'];
                $data['openid']=$user['openid'];
                $data['create_time']=time();
                if($jackpot['type']==0){
                    if(!empty($user['redpack_openid'])){
                        $data['redpack_openid']=$user['redpack_openid'];}
                    $data['price']=$jackpot['price'];
                }else{
                    $data['type']=$jackpot['type'];}
                Db::startTrans();
                try{
                    db('jackpot')->where('id',$jackpot['id'])->update(['state'=>0]);
                    db('user')->where('openid',$openid)->update(['number'=>$user['number']+1]);
                    db('winprize')->insert($data);
                    Db::commit();
                    return json(['code'=>0,'type'=>$jackpot['type']]);
                } catch (\Exception $e) {
    
                    Db::rollback();
                    return json(['code'=>3,'msg'=>'事务出现异常!']);}
            }else{
                return json(['code'=>1,'msg'=>'没有抽奖机会']);}
        }
        return json(['code'=>-1,'msg'=>'错误']);
    }

    nginx.conf:

    user www www;

    worker_processes 16;

    error_log /home/wwwlogs/nginx_error.log crit;

    pid /usr/local/nginx/logs/nginx.pid;
    google_perftools_profiles /tmp/tcmalloc;

    events

    {
        use epoll;
        worker_connections 65535;
        multi_accept on;
    }
    

    http

    {
        include       mime.types;
        default_type  application/octet-stream;
    
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
    
        sendfile   on;
        tcp_nopush on;
    
        keepalive_timeout 60;
    
        tcp_nodelay on;
    
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
    
        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";
    
        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
    
        server_tokens off;
        access_log off;
    

    server

    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;
    
        #error_page   404   /404.html;
    
        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
    
        include enable-php.conf;
    
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }
    
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
    
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }
    
        location ~ /.well-known {
            allow all;
        }
    
        location ~ /\.
        {
            deny all;
        }
    
        access_log  /home/wwwlogs/access.log;
    }

    include vhost/*.conf;
    }

    查阅了一下nginx与php错误日志,没有发现有异常记录。请大神帮忙分析一下

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 共 0 条
    • 胖元帅 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部