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>';
}
}
谢谢。让我的主持人把时间限制从2分钟延长到一小时。永远拿走他们。 – decaye 2012-07-30 16:26:38