2012-08-11 4 views
1

나는 죽은 상품을 우리의 시스템에서 검사 할 것입니다. 아이템 (100.000+ 드레스)의 양 때문에 전체 DB 테이블을 100 번 반복합니다.PHP 루프가 완료되지 않았습니까?

100 개 세트를 검사 한 후, 통과 한 시간을 표시하는 메시지를 출력합니다.

문제 : 어떻게 든 2400-2500으로 중단됩니다 (아래 참조).

문제의 위치를 ​​알고 계십니까?

어쩌면 증가가 문제일까요? 왜, 또한 http://ca2.php.net/manual/en/function.set-time-limit.php

:

// get the amount of all rows to enable pagination later 
$AllRowsResponse = mysql_query("SELECT COUNT(*) AS Count FROM ".$targettablename." WHERE 1") or die ("Error #111231".mysql_error()); 
mysql_close($conn); 

// write amount of rows into variable 
$AllRows = mysql_fetch_array($AllRowsResponse) or die (mysql_error()); 
$RowCount = $AllRows["Count"]; 
//print "<br>all rows in table: " . $RowCount ;flush(); 
print "<br><h1>CHECKING ".$TargetTable." FOR DEAD PRODUCTS</h1><br>"; 

$deletedprods = 0; // set up counter for deleted product 
$i = 0; // counter 
$increment = 100; // increment steps 
$timetotalstart = microtime(true); // variable to measure each requests time. this is the beginning time 
$md5deadimage1 = md5(file_get_contents("www.mydomain.com/dead1.jpg")); // get md5 of "not available" pic ONCE 
$RowsMinusDeleted = $RowCount - $deletedprods; // when deleting a prod, dont look for rows that arent there anymore 

while ($i <= $RowsMinusDeleted) { // as long as the counter is below the rowcount, there are still rows to check 

    $limitstart = $i; 
    $limitend = $i + $increment; //MAYBE PROBLEM IS HERE??? 

    $conn = ConnectToDB(); 

    $ProductIds = mysql_query("SELECT ProductId,Image,Deeplink FROM ".$targettablename." WHERE 1 LIMIT " . $limitstart . "," . $limitend) or die ("Error #11124".mysql_error()); 
    mysql_close($conn);  

    $i = $i + $increment; // increase the counter by the above defined increment 


    //print " DEAD-MD5:" & $md5deadimage1;flush(); 

    print "<br>(Checking items " . $limitstart . "-" . $limitend . "(of ". $RowCount . " total))";flush(); 
    //$rowCount = mysql_num_rows($ProductIds); 
    //print "<br>amount of ids etc in array: " . count($rowCount) ;flush(); 
    $timeloopstart = microtime(true); 
    // write every productId into an array 
    while ($row = mysql_fetch_array ($ProductIds)) { 

     // get md5 of current product image 
     $md5deadimage2 = md5(file_get_contents($row['Image'])); 
     if ($md5deadimage1 == $md5deadimage2) { // if current file md5 is equal to any "dead picture", show it/delete it 

      $deletedprods++; 
      $conn = ConnectToDB(); 

      print "<a href=\"".$row['Deeplink']."\" target='_blank'><img src=\"".$row['Image']."\"></a>";flush(); 

      mysql_query("DELETE FROM ".$targettablename." WHERE `ProductId`=".$row['ProductId']."") or die ("Error #11125".mysql_error()); 

      mysql_close($conn); 
     } 
     //} // end if 
     $RowsMinusDeleted = $RowCount - $deletedprods; 
    } // end while 
    $timeloopend = microtime(true); 
    $timelooptotal = $timeloopend - $timeloopstart; 
    print "<-- above took " . floor($timelooptotal) . " seconds"; 
} 

$timetotalend = microtime(true); 
$timetotal = $timetotalend - $timetotalstart; 
print "<h2> whole request took " . floor($timelooptotal/60) . " minutes"; 
print "\n<h2>Updated ".$TargetTable.". Deleted <b>".$deletedprods."</b> old products</h2>"; 

가 여기 내 스크립트가 수행 내용은 다음과 같습니다 :

CHECKING dresses FOR DEAD PRODUCTS 



(Checking items 0-100(of 134902 total))<-- above took 17 seconds 

(Checking items 100-200(of 134902 total))<-- above took 34 seconds 

(Checking items 200-300(of 134902 total))<-- above took 48 seconds 

(Checking items 300-400(of 134902 total))<-- above took 68 seconds 

(Checking items 400-500(of 134902 total))<-- above took 82 seconds 

(Checking items 500-600(of 134902 total))<-- above took 94 seconds 

(Checking items 600-700(of 134902 total))<-- above took 109 seconds 

(Checking items 700-800(of 134902 total))<-- above took 125 seconds 

(Checking items 800-900(of 134902 total))<-- above took 136 seconds 

(Checking items 900-1000(of 134902 total))<-- above took 146 seconds 

(Checking items 1000-1100(of 134902 total))<-- above took 162 seconds 

(Checking items 1100-1200(of 134902 total))<-- above took 185 seconds 

(Checking items 1200-1300(of 134902 tota l))<-- above took 199 seconds 

(Checking items 1300-1400(of 134902 total))<-- above took 212 seconds 

(Checking items 1400-1500(of 134902 total))<-- above took 237 seconds 

(Checking items 1500-1600(of 134902 total))<-- above took 277 seconds 

(Checking items 1600-1700(of 134902 total))<-- above took 287 seconds 

(Checking items 1700-1800(of 134902 total))<-- above took 292 seconds 

(Checking items 1800-1900(of 134902 total))<-- above took 304 seconds 

(Checking items 1900-2000(of 134902 total))<-- above took 305 seconds 

(Checking items 2000-2100(of 134902 total))<-- above took 337 seconds 

(Checking items 2100-2200(of 134902 total))<-- above took 393 seconds 

(Checking items 2200-2300(of 134902 total))<-- above took 368 seconds 

(Checking items 2300-2400(of 134902 total))<-- above took 375 seconds 

(Checking items 2400-2500(of 134902 total)) 
+6

이 - 당신이하고 set_time_limit과 스크립트를 시도했다가 (0); ? – MimiEAM

+0

-4 down vote \t Wahooo - 코드가 풍부하고 시작하기가 어렵습니다. 문제 영역을 약간 아래로 향하게하십시오. –

+0

[MySQLi] (http://php.net/manual/en/book.mysqli.php) 또는 [PDO] (http://php.net/manual/en/book.pdo.php)를 사용하십시오. mysql_ * 함수는 더 이상 사용되지 않습니다. –

답변

3

사용 "set_time_limit(0)"

더 많은 정보를 원하시면 여기 여기

코드입니다 데이터에 대한 새 연결을 만드는 경우 모든 반복마다 기본? 그럴 필요는 없습니다. 하나의 연결을 만들어 사용하십시오.

또한 미래에 자신의 문제 해결을위한 팁, 사용 error_reporting(E_ALL);

스크립트가 시간 초과 될 수
+0

안녕하세요 @ 에반, 답장을 보내 주셔서 감사합니다. 나는 error_reporting (E_ALL)을 시도합니다. 그건 그렇고 : 나는이 일을 너무 자주 cronjob을 사용합니다. 아마 cronjob의 문제일까요? – ItsMeDom

+0

@DoJoChi : 시간 제한 설정을 시도 했습니까? –

+0

cronjob을 설정하여 출력을 보낼 수도 있습니다. – Eva

관련 문제