search

Home  >  Q&A  >  body text

php request timeout

$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'));
			}
		}
	}         
    for($i=2;$i<=$allRow;$i++){
        switch ($express_id) {
            case 1:
                //接口请求参数
                $post_info = [
                    
                ];
                //请求接口
                $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] = [
                        
                    ];
                    //更新用户信息
                    $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;
            default:
                # code...
                break;
        }
    }
    //循环结束执行业务逻辑


User uploads the form->php background parsing the form->Requests how many records the external interface table has in the loop body through the for loop and how many times it loops->When all for loops are executed Process other business after completion

The current problem is that when the table has more than 500 data, the execution time of the entire for loop body is too long, causing the server to timeout

How to solve this situation through the other party's interface? Receive up to 5 tone data

The above is an example of my code. How to solve this problem? If the user experience is not good if the request time is changed, the waiting time is too long


张少伟张少伟2102 days ago934

reply all(0)I'll reply

No reply
  • Cancelreply