我有下面的腳本,經過一定量的迭代後停止沒有錯誤。當它使用的圖像是〜4MB時,腳本在大約10次迭代後停止。當圖像大約1MB時,腳本在約30次迭代後停止。當圖像較小時,腳本可以進行500次迭代。它似乎沒有超時,因爲它發生在每次不同的時間。PHP腳本突然停止(imagecopyresampled)
當我在我自己的機器上使用xxamp測試它時,沒有任何錯誤,並且腳本完美無缺。
我猜這是一些類型的內存問題?在記憶方面,我完全沒有經驗和無知。
編輯: 我在imagecopyresampled函數之前和之後放置一個回聲。腳本似乎停止在這個功能上。
這裏是我的循環,對目錄中的每個文件雲:
while (false !== ($filer = readdir($handle))) {
if (is_file($srcDir . '/' . $filer)) {
set_time_limit(20);
$counter++;
$total = $x;
$percent = intval($counter/$total * 100)."%";
// Javascript for updating the progress bar and information
echo '<script language="javascript">
document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#333;\"> </div>";
document.getElementById("information").innerHTML="'.$counter.' images processed.";
</script>';
//location/filename variable
$filename = $srcDir . '/' . $filer;
// This is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
// Send output to browser immediately
flush();
//get the extension of the image
$path_parts = pathinfo("$filename");
$ext = strtolower ($path_parts['extension']);
$width = 100;
$height = 100;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output the small image
imagejpeg($image_p, "$destDir/$filer", 100);
//Move the big image
rename($srcDir . '/' . $filer, $destDirbig . '/' . $filer);
echo $counter;
}
}
我可能是錯的,但我不知道,'假==($文件= READDIR($句柄))'是正確的語法。 '!='是'不等於'的標準。如果你正在嘗試文本,如果它是'完全不相等',我想你想'!(($ file = readdir($ handle))=== false)' –