[請益] 跑超久0.0?

看板PHP作者 (Reloading......)時間15年前 (2010/10/24 12:29), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/1
如題 雖然已經有心理準備跑GD的函式會很慢 但是這個程式碼跑了5分鐘還沒跑完= = 而且都卡在一些奇怪的地方 (所以才加了第一行= =) 請問各位大大 我該怎麼做讓整個程式加快呢0.0? 感謝 程式碼如下 <?php set_time_limit(0); $yea=date(Y); $mon=date(m); $day=date(d); $hou=date(H); $min=date(i); $min2=round(date(i),-1); if($min >= 30){ $min=30; $mi=3; }else{ $min="00"; $mi=0; } //生成日期 $date1=$day.$hou.$mi; $date2=$yea."-".$mon."-".$day."-".$hou."-".$min; $date3=$yea."-".$mon."-".$day."_".$hou.$min2; //生成cwb原圖網址 $url01="http://www.cwb.gov.tw/V6/observe/rainfall/Data/hka".$date1.".jpg"; $url02="http://www.cwb.gov.tw/V6/observe/satellite/Data/HSAO/HSAO-".$date2.".jpg"; $url04="http://www.cwb.gov.tw/V6/observe/satellite/Data/HS1Q/HS1Q-".$date2.".jpg"; $url06="http://www.cwb.gov.tw/V6/observe/radar/Data/MOS2_1024/".$date3.".2MOS0.jpg"; // $agetheaders=@get_headers($url01); while( ! preg_match("|200|",$agetheaders[0])){ if($mi==3){ $mi=0; } else { $mi=3; $hou=$hou-1; while(strlen($hou) == 1){$hou = "0".$hou;} } } //作圖rain $img2p=imagecreatefromjpeg($url01); $img2o=imagecreatefromjpeg("images/orain.jpg"); imagecopyresampled ($img2o,$img2p,720,180,0,0,720,720,400,400); imagejpeg($img2o,"images/rain1.jpg"); $hou=date(H); // $agetheaders=@get_headers($url02); while( ! preg_match("|200|",$agetheaders[0])){ if($min==30){ $min="00"; } else { $min=30; $hou=$hou-1; while(strlen($hou) == 1){$hou = "0".$hou;} } } //作圖sea $img3p=imagecreatefromjpeg($url04); $img4p=imagecreatefromjpeg($url02); $img3o=imagecreatefromjpeg("images/osea1.jpg"); $img4o=imagecreatefromjpeg("images/osea2.jpg"); imagecopyresampled ($img3o,$img3p,720,180,0,0,720,720,800,800); imagecopyresampled ($img4o,$img4p,720,180,0,0,720,720,800,800); imagejpeg($img3o,"images/sea1.jpg"); imagejpeg($img4o,"images/sea2.jpg"); $hou=date(H); // $agetheaders=@get_headers($url06); while( ! preg_match("|200|",$agetheaders[0])){ if($min2==0){ echo $min2; $min2=50; $hou=$hou-1; while(strlen($hou) == 1){$hou = "0".$hou;}} else { echo $min2; $min2=$min2-10; while(strlen($min2) == 1){$min2 = "0".$min2;} } } //作圖radar $img1p=imagecreatefromjpeg($url06); $img1o=imagecreatefromjpeg("images/orad.jpg"); imagecopyresampled ($img1o,$img1p,720,180,0,0,720,720,600,600); imagejpeg($img1o,"images/rad1.jpg"); ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.67.187

10/24 13:33, , 1F
microtime自己噴出來看一下 找bottleneck
10/24 13:33, 1F

10/24 17:19, , 2F
找到問題了 感謝
10/24 17:19, 2F
文章代碼(AID): #1CmxOfjt (PHP)
文章代碼(AID): #1CmxOfjt (PHP)