0

Any advise on how to increase performance for the following PHP script? The entire set of code is nested under 2 level foreach with an if clause. It took about 30 seconds to load now.

foreach ($result as $_type => &$type_v) {
    foreach ($type_v as $xiaji_id => &$v) {
        if($lvl == 2){
            $beginDate = date("Y-m-d", strtotime($BeginDatetime));
            $endDate = date("Y-m-d", strtotime($EndDatetime));
            
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, "http://".$_SERVER['SERVER_NAME']."/Admin/Report/Detail1?id=" . $v['g_name']. "%2C60900733116476424%2C6007323122&type=1&play=0&item=0&num=&bdate=".$beginDate."&edate=".$endDate."&settle=1&users_json=%5B%5D&ids_json=%5B%5D");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            $output = curl_exec($ch);
            curl_close($ch);
            $str=preg_replace("/[\t\n\r]+/","",$output);
            
            $pattern = '/Paid\:<\/span> <span.*?>(.*?)<\/span>/';
            preg_match($pattern, $str, $matches);
            $totalMatches += $matches[1];
        }
    }
}
ironman
  • 11
  • 1
  • 3

0 Answers0