Php 对于While循环脚本,暂停/重新启动以在最大执行时间下运行
我是用手动的方式做的,但我想可能有一种更自动的方式来做。下面的脚本必须调整1000个文件夹的大小,每个文件夹中的图像总数超过100K(而不是每个文件夹中的100K)。我只有两分钟的最长执行时间让它运行。它可以在两分钟内完成大约10个文件夹。但是,我真的只想让脚本在两分钟结束前暂停…然后在它停止的地方重新开始…希望,重新启动它的最大执行时间。我不知道sleep()是否能做到这一点-sleep可能会计入执行时间,但不确定 手动方式是将$count变量增加10,然后将while循环中的i$也增加10。因此,它将从它停止的地方开始,一次处理10个文件夹。刷新以运行它。目前我也没有cron访问权限 这是剧本Php 对于While循环脚本,暂停/重新启动以在最大执行时间下运行,php,Php,我是用手动的方式做的,但我想可能有一种更自动的方式来做。下面的脚本必须调整1000个文件夹的大小,每个文件夹中的图像总数超过100K(而不是每个文件夹中的100K)。我只有两分钟的最长执行时间让它运行。它可以在两分钟内完成大约10个文件夹。但是,我真的只想让脚本在两分钟结束前暂停…然后在它停止的地方重新开始…希望,重新启动它的最大执行时间。我不知道sleep()是否能做到这一点-sleep可能会计入执行时间,但不确定 手动方式是将$count变量增加10,然后将while循环中的i$也增加10。
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>';
}
}
类DevTestHelper{
//这将检查所有全尺寸图像,并将图像调整到所需文件夹中
函数resizeGalleryImage($destFolder、$width、$height、$isCrop=false){
$count=1000;
$source=JPATH_SITE.“/images/gallery/full”;
$dest=JPATH_SITE.“/images/gallery/”$dest文件夹;
回波“处理图像
”;
//循环浏览/full目录中的所有1000个文件夹0到999
对于($i=0;$i<$count;$i++){
$iPath=$source.'/'.$i;
if(is_dir($iPath)){
$h=opendir($iPath);
//循环浏览编号文件夹中的所有文件
而($entry=readdir($h)){
//只读取文件
如果($entry!=“&&$entry!=”。“&&&!is_dir($entry)){
$img=新GImage($source./'.$i./'.$entry);
$tmp=$img->resize($width,$height,true,3);
如果($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“在以下位置创建调整大小的图像时出错:”.$destination.“
”;
}
//回显$entry.“
”;
}
}
回显“已处理:”.$i.“文件夹
”;
}
}
您有几个不同的选择:
谢谢。让我的主人把时间限制从2分钟延长到了一小时。他们永远都在浪费时间。