PHP server request timed out

 if($request->isPost()){
            $file =input("post.avatar");
            if(!$file){
                $this->error("csv,xls,xlsx");
            }
            $filePath = ROOT_PATH . DS . "public" . DS . $file;
            if (!is_file($filePath)) {
                $this->error("");
            }
            $PHPReader = new \PHPExcel_Reader_Excel2007();
            if (!$PHPReader->canRead($filePath)) {
                    $PHPReader = new \PHPExcel_Reader_Excel5();
                if (!$PHPReader->canRead($filePath)) {
                        $PHPReader = new \PHPExcel_Reader_CSV();
                        $PHPReader->setInputEncoding("GBK");
                    if (!$PHPReader->canRead($filePath)) {
                        $this->error(__("Unknown data format"));
                    }
                }
            }
            $uptime = time();//
            $num = input("post.num");//
            $id = input("post.gid");//id
            $uid = $this->auth->id;//id
            $uname = $this->auth->username;
            $yu_money = $this->auth->money;//
            $level = $this->auth->level;//
            $store_id = input("post.store_id");//
            $store_info = Db::name("send_store")->where("id",$store_id)->find();//
            $is_multiple = $store_info["is_multiple"];
            if($is_multiple==0){
                $num = 1;
            }
            $express_id = $store_info["express_id"];//
            $express_price = get_price($level,$express_id);//
            $goods_info = Db::name("goods")->where("id",$id)->find();
            $weight = $goods_info["weight"];
            $goods_price = $goods_info["price"];//
            $total_fee = $num*$goods_price+$express_price;//
            $send_store = $store_info["send_code"];//
            $store_name = $store_info["store_name"];//name
            $father_code = trim(get_father_code($id,$express_id));//
            $PHPExcel = $PHPReader->load($filePath); //
            $currentSheet = $PHPExcel->getSheet(0);  //
            $allRow = $currentSheet->getHighestRow(); // 
            $pttype = $currentSheet->getCell("A1")->getValue();//
            $leijia = "";
            $continue_num = 0;
            for($i=2;$i<=$allRow;$iPP){
                if($yu_money < $total_fee){
                    $upinfo=Db::name("upinfo");
                    $info["user_id"] = $uid;
                    $info["exnum"] = $allRow-1;//
                    $info["oknum"] = $i-2;//
                    $info["tableid"] = $uptime;//id
                    $info["expressid"] = $express_id;
                    $info["vars"] = "";
                    $upinfo->insert($info);
                    $this->error("".($i-2)."",url("Express/tblist"));
                }
                if($pttype==""){//
                    $out_order_no = $currentSheet->getCell("A".$i)->getValue();//
                    $address_ren =  $currentSheet->getCell("O".$i)->getValue();//
                    $address_array = preg_replace("/()|(,)/","",$currentSheet->getCell("P".$i)->getValue());//
                    $address_hao = preg_replace("/\W/","",$currentSheet->getCell("S".$i)->getValue());//
                }else if($pttype==""){//
                    $out_order_no =  $currentSheet->getCell("B".$i)->getValue();
                    $address_ren =  $currentSheet->getCell("O".$i)->getValue();//
                    $address_hao = preg_replace("/\W/","",$currentSheet->getCell("P".$i)->getValue());// 
                    $add_s =  $currentSheet->getCell("Q".$i)->getValue();//
                    $add_c =  $currentSheet->getCell("R".$i)->getValue();//
                    $add_a =  $currentSheet->getCell("S".$i)->getValue();//
                    $add_d =  $currentSheet->getCell("T".$i)->getValue();//
                    $address_array = $add_s." ".$add_c." ".$add_a." ".$add_d;//
                }else if($pttype==""){//
                    $out_order_no =  $currentSheet->getCell("A".$i)->getValue(); 
                    $address_array = preg_replace("/()|(,)/","",$currentSheet->getCell("B".$i)->getValue());//
                    $address_ren =  $currentSheet->getCell("C".$i)->getValue();//
                    $address_hao = preg_replace("/\W/","",$currentSheet->getCell("D".$i)->getValue());//
                }else{
                    $this->error("");
                }
                $out_order_no = preg_replace("-sharp -sharp","",$out_order_no);//
                $address_hao = preg_replace("-sharp -sharp","",$address_hao);//
                $address_ren = preg_replace("-sharp -sharp","",$address_ren);//
                //
                if(empty($out_order_no)){
                    $leijia = $leijia."".$i.",";
                    continue;
                }
                $isorder = Db::name("express")->where("out_order_no",trim($out_order_no))->find();
                //
                if ($isorder)
                {   
                    $leijia = $leijia."".$i."".$isorder["out_order_no"].",";
                    continue;
                }
                //
                if(empty($address_hao)){
                    $leijia = $leijia."".$i.",";
                    continue;
                }
                //
                if(empty(preg_replace("-sharp -sharp","",$address_array))){
                    $leijia = $leijia."".($i).",";
                    continue;
                }
                //
                if(empty($address_ren)){
                    $leijia = $leijia."".$i.",";
                    continue;
                }
                //
                $addrlist = explode(" ",$address_array);
                $addrlist = array_filter($addrlist);
                $addrlist = array_values($addrlist);
                if(count($addrlist)<4)
                {
                    $leijia = $leijia."".$i.",";
                    continue;
                }
                // ini_set("display_errors","On");
                // error_reporting(E_ALL);
                switch ($express_id) {
                    case 1:
                        //
                        $post_info = [
                            "accessToken"=>config("get_yto_config.token"),
                            "storehouseCode"=>$send_store,"goodsCode"=>$father_code,
                            "receiver"=>$address_ren,"receiverPhone"=>$address_hao,
                            "receiverProvinceName"=>$addrlist[0],"receiverCityName"=>$addrlist[1],
                            "receiverAreaName"=>$addrlist[2],"receiverAddress"=>$addrlist[3],
                            "thirdOrderNo"=>$out_order_no,"goodsNum"=>$num,"shipperName"=>$uname
                        ];
                        //
                        $json = sendRequest("",$post_info,"POST");
                        $return = json_decode($json,1);
                        $code = $return["code"];
                        if($code==0){
                            $return_data = $return["data"];
                            $taskid = $return_data["recordId"];
                            //
                            $result = [];
                            $result[$i] = [
                                "user_id"=>$uid,
                                "express_no"=>"0",
                                "out_order_no"=>$out_order_no,
                                "expressid"=>$express_id,
                                "weight"=>$weight,
                                "price"=>$total_fee,
                                "num"=>$num,
                                "goods"=>$id,
                                "addressee"=>$address_ren,
                                "a_mphone"=>$address_hao,
                                "all_address"=>$address_array,
                                "taskid"=>$taskid,
                                "sender"=>$store_name,
                                "tableid"  => $uptime,
                                "from"  => 1 
                            ];
                            //
                            $retu = model("express")->saveAll($result);
                            $yu_money = $yu_money-$total_fee;
                            \app\common\model\User::score($score=0,"-".$total_fee,$uid,"".$retu[$i]["id"]);
                            $continue_num = $continue_num+1;
                        }else{
                            $this->error($return["msg"]);
                        }
                        break;
                    case 4:
                        //
                        $orderParams = [];
                        $orderParams[0] = [
                            "apiOrderId"=>$out_order_no,//
                            "buyerName" =>$address_ren,//
                            "buyerMobile"=>$address_hao,//
                            "buyerAddr"=>$address_array,//
                            "storeType"=>$send_store,//
                            "kuaidiName"=>get_express_name($express_id)
                        ];
                        $orderParams = json_encode($orderParams);
                        $post_info = [
                            "partnerId"   =>"",//ID
                            "itemId"      =>$father_code,//
                            "orderParams" =>$orderParams,//
                            "validation"   =>md5($father_code.$orderParams.""."")
                        ];
                        $json = sendRequest("",$post_info,"post");
                        $return  = json_decode($json,1);
                        if($return["result"]===1){
                            $return_info = $return["orders"][0];
                            $out_order_no = $return_info["apiOrderId"];//
                            $express_no = $return_info["expressNo"];//
                            //
                            $result = [];
                            $result[$i] = [
                                "user_id"=>$uid,
                                "express_no"=>$express_no,
                                "out_order_no"=>$out_order_no,
                                "expressid"=>$express_id,
                                "weight"=>$weight,
                                "price"=>$total_fee,
                                "num"=>$num,
                                "goods"=>$id,
                                "addressee"=>$address_ren,
                                "a_mphone"=>$address_hao,
                                "all_address"=>$address_array,
                                "sender"=>$store_name,
                                "tableid"  => $uptime,
                                "from"  => 1 
                            ];
                            //
                            $retu = model("express")->saveAll($result);
                            $yu_money = $yu_money-$total_fee;
                            \app\common\model\User::score($score=0,"-".$total_fee,$uid,"".$retu[$i]["id"]);
                            $continue_num = $continue_num+1;
                        }else{
                            $this->error($return["message"]);
                        }
                        break;
                    default:
                        -sharp code...
                        break;
                }
            }
            $upinfo=Db::name("upinfo");
            $info["user_id"] = $uid;
            $info["exnum"] = $allRow-1;//
            $info["oknum"] = $continue_num;//
            $info["tableid"] = $uptime;//id
            $info["expressid"] = $express_id;
            $info["vars"] = $leijia=="" ?"":$leijia;
            $upinfo->insert($info);
            $this->success("".($continue_num)."",url("Express/exlist"));
        }

above is my code for handling business logic. The other side interface can only accept up to five pieces of data at a time.
after I read the form, I loop a record of reading the form through for. I request the external interface once in the loop. Today, the form uploaded by a customer is too large, so the whole cycle time is too long. How can I solve this problem? Please give me some advice, everyone.

Php
Jul.06,2022

use message queue to implement asynchronous processing of time-consuming tasks


$allRow is the maximum number of read entries?
you can try to convert the acquired array to collect ()
and then call chunk () slicing
library operation as far as possible.


use message queue, asynchronize, and do not use this excel package, use csv text files

Menu