I keep seeing Waiting for Cache and it takes at least 30 minutes to get 
the response.
Is there a better way?
Here's the link: http://tapnapp.co/planning/phpScripts/getFullViewTasks.php?counter=1&sDateHour=1525154400&eDateHour=1527793200
And here is the code:
<?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);  
}
?>
So what is wrong with this if anyone can understand? Is that because of mysql or because of the php?
 
    