Php:这个Php脚本怎么会花费太长时间来响应?

Php:这个Php脚本怎么会花费太长时间来响应?,php,mysql,Php,Mysql,我一直看到在等待缓存,至少需要30分钟才能获得缓存 回应。 有更好的办法吗 以下是链接: 代码如下: <?php if (isset($_GET['counter'])) { require_once '../functions.php'; $sDateHour = $_GET['sDateHour']; $eDateHour = $_GET['eDateHour']; $now = time() - 24*60*60; $fn = new

我一直看到
在等待缓存
,至少需要30分钟才能获得缓存 回应。 有更好的办法吗

以下是链接:

代码如下:

<?php

if (isset($_GET['counter'])) {
    require_once '../functions.php';

    $sDateHour = $_GET['sDateHour'];
    $eDateHour = $_GET['eDateHour'];

    $now = time() - 24*60*60;
    $fn = new Func;
    $fn->select('id_profile, groupe','profile',''," date_f_contract>='$now' AND groupe>0");

    $sel = new Func;
    $getHrName = new Func;

    while ($row = mysqli_fetch_assoc($fn->select)) {
        $pr_id = $row['id_profile'];

        $sel->select('*','counter',''," from_interval>='$sDateHour' AND to_interval<='$eDateHour' AND id_profile='$pr_id'");
        $nr= mysqli_num_rows($sel->select);

        if ($nr > 0) {
            //here we have to do the total counter
            $totalCounter = 0;
            $from_interval = 0;
            $to_interval = 0;
            $name = "";

            $tmp_id_profile = 0;
            $tmp_f_int = 0;
            $tmp_to_int = 0;

            while ($r = mysqli_fetch_assoc($sel->select)) {
                $frint = $r['from_interval'];
                $toint = $r['to_interval'];
                //$counter_ct = $r['counter'];
                $totalCounter += $counter_ct;

                $getHrName->select('libelle AS lbl, COUNT(libelle) AS totalHr',"horraire",""," date_heure_deb>='$frint' AND date_heure_fin<='$toint' AND id_profile='$pr_id' GROUP BY libelle ORDER BY totalHr DESC LIMIT 1");
                $rr = mysqli_fetch_assoc($getHrName->select);
                $r['hrname'] = $rr['lbl'];
                $name = $rr['lbl'];
                $r['counter'] = $rr['totalHr'];
                /*
                $from_interval=$frint;
                $to_interval = $toint;
                */
                $row['tasks'][] = $r;
            }
            /*
            $r['counter']=$totalCounter;
            $r['from_interval']=$from_interval;
            $r['to_interval']=$to_interval;
            $r['hrname']=$name;*/
            //$row['tasks'][]=$r;
        } else {
            /*
            id_counter: "1",
            id_profile: "17",
            from_interval: "1519887600",
            to_interval: "1519934400",
            counter: "18"}
            */

            /*
            $fake['id_counter']=0;
            $fake['id_profile']=$pr_id;
            $fake['from_interval']=$sDateHour;
            $fake['to_interval']=$eDateHour;
            $fake['counter']=0;
            $row['tasks'][]=$fake;
            */
        }
        $res[] = $row;  
    }

    $temp['data'] = $res;
    $fn->deconnect();
    $sel->deconnect();
    echo json_encode($temp, JSON_PRETTY_PRINT);  
}

?>

这真的很难说,尤其是因为我们不知道您的数据集。尝试一些日志记录,看看它要去哪里,需要多长时间,等等。这是一个很难回答的问题,我唯一能建议的是通过记录代码的不同部分来找到瓶颈。从imo的查询开始。这可能有助于您进行调试:这个问题基本上是:我建议对表进行索引,并将两个查询合并为一个查询,这样就不需要PHP循环。。此外,您还需要防止SQL注入,这在当前代码中似乎是可能的。。