2012-07-27 34 views
1

我這樣做的手動方式,但我想可能有一個更自動的方式來做到這一點。下面的腳本必須在每個文件夾中統一調整1000個具有超過100K圖像的文件夾(每個文件夾中不包含100K)。我只有兩分鐘的max_execution_time才能運行。它可以在兩分鐘內完成大約10個文件夾。但是,實際上我只是希望腳本在兩分鐘之前暫停......然後重新開始,然後重新開始它的最大執行時間。我不知道sleep()是否可以這樣做 - 睡眠可能會計入執行時間,不確定。對於While循環腳本暫停/重新啓動在max_execution_time下運行

手動方法是將$ count變量增加10,然後將while循環中的$增加10。因此,它會從停止位置開始,一次執行10個文件夾。刷新以運行它。目前我也沒有cron訪問權限。

這裏的腳本...

class DevTestHelper { 


//This will Go through all full size images and resize images into requested folder 
function resizeGalleryImages($destFolder, $width, $height, $isCrop = false) { 

$count = 1000; 

$source = JPATH_SITE."/images/gallery/full"; 
$dest = JPATH_SITE."/images/gallery/".$destFolder; 

echo 'Processing Images<br>'; 

//Loop through all 1000 folders 0 to 999 in the /full dir 
for($i=0; $i < $count;$i++) { 
    $iPath = $source.'/'.$i; 
    if(is_dir($iPath)) { 

      $h = opendir($iPath); 
      //Loop through all the files in numbered folder 
      while ($entry = readdir($h)) { 

     //only read files 
       if ($entry != "." && $entry != ".." &&  !is_dir($entry)) { 
      $img = new GImage($source.'/'.$i.'/'.$entry); 

        $tmp = $img->resize($width, $height, true, 3); 

        if($isCrop) { 
         $tmpWidth = $tmp->getWidth(); 
         $tmpHeight = $tmp->getHeight(); 

         $xOffset = ($tmpWidth - $width)/2; 
         $yOffset = ($tmpHeight - $height)/2; 

         $tmp->crop($width, $height, $xOffset, $yOffset, false, 3); 
        } 

        $destination = $dest.'/'.$i.'/'.$entry; 

        if(!$tmp->toFile($destination)) { 
         echo 'error in creating resized image at: '.$destination.'<br>'; 
        } 

       //echo $entry.'<br>'; 
     } 

      } 

     echo 'Processed: '.$i.' Folder<br>'; 

    } 
} 

回答

0

您有幾種不同的選擇:

  1. 有填充隊列和處理隊列另一種語言的腳本。
  2. 產生多個工人腳本來並行處理
  3. 的處理後的每個調整,你的循環中使用的set_time_limit(X)延長腳本超時,這樣只要數據被成功處理,它將繼續運行
+1

謝謝。讓我的主持人把時間限制從2分鐘延長到一小時。永遠拿走他們。 – decaye 2012-07-30 16:26:38

相關問題