douyi2664 2019-06-25 16:33
浏览 68

具有多个AJAX调用的页面(有时)需要很长时间才能加载

I'll try to be as thorough as possible.

I have an application written in PHP using the codeigniter framework.

On a few, but one particular page I have a lot of information to show therefore thought it a good idea to split it all into multiple Ajax calls. It's been like this for at least the last 2 years yet recently my customers are complaining of speed issues.

I've tested the page and 6/10 times it loads with out issue.

The page has 6 ajax calls as shown in the image, most taking less than 500ms to run.

enter image description here

However, on roughly 4/10 page reloads it will hang causing at least 2 of the ajax calls to take way over 5 seconds to complete, even as much as 20 seconds sometimes.

enter image description here

Here's a snippet of code:

    $('#table_booking_details').dataTable({
    "autoWidth": false,
     "responsive" : {
        "details": false,
    },
    "ajax": {
        "url"  : "/admin/booking/dt_get_rental_date_times/",
        "type" : "POST",
        "data" : {
            "rental_index" : $('#rental_index').val() 
        }
    },
    "serverSide" : true,
    "processing" : true,
});


    public function dt_get_rental_date_times()
{
    $rental_index       = $this->input->post('rental_index');
    $search             = $this->input->post('search');
    $search_param       = $search['value'];

    $sort               = $this->input->post('order');
    $sort_column_index  = $sort['0']['column'];
    $sort_direction     = $sort['0']['dir'];

    $length             = $this->input->post('length');
    $start              = $this->input->post('start');

    $sort_column_array  = array("0" => "collection_date_time", "1" => "return_date_time", "2" => "vehicle_registration", "3" => "(return_date_time - collection_date_time)", "4" => "rental_date_time_cost");

    $sort_column        = $sort_column_array[$sort_column_index];


    $rental_date_times_result = $this->rentals_model->dt_get_rental_date_times($length, $start, $sort_column, $sort_direction, $search_param, $rental_index);

    $rental_date_times          = $rental_date_times_result['rows'];
    $rental_date_times_count    = $rental_date_times_result['num_rows'];

    $data['recordsTotal']        = $rental_date_times_count;
    $data['recordsFiltered']     = $rental_date_times_count;
    $results                     = array();

    $i = 0;

    foreach ($rental_date_times as $rent) 
    {           
        $days = ceil(($rent->return_date_time - $rent->collection_date_time) / 60 / 60 / 24);

        $actions = '';

        if($rent->swapover == 1)
        {
            $actions = 'Yes';
        }
        else
        {
            $actions = 'No';
        }

        $results[] = array(
                "DT_RowId"      => "rentalperiod_" . $rent->rental_date_time_index,
                "DT_RowClass"   => 'linkable_row',
                "0"             => timestamp_to_date_time($rent->collection_date_time),
                "1"             => timestamp_to_date_time($rent->return_date_time),
                "2"             => $rent->vehicle_registration,
                "3"             => $days,
                "4"             => $rent->rental_date_time_cost,
                "5"             => $actions
        );
    }

    $data['data'] = $results;

    echo json_encode($data);
}

Firstly is it likely this is a new thing that people are just starting to notice, seems a little strange it would just randomly start happening.

Any suggestions what I can do to improve it without moving everything back to old school php with page reloads.

Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100