For While Loop Script pause/restart to run under max_execution_time
===

I was doing this in a manual way, but i was thinking there may be a more automatic way to do this. The below script has to resize 1000 folders with more than 100K images collectively in each folder (Not 100K in each folder). I only have two minutes of max_execution_time for it to run. It can do about 10 folders in two minutes. But, really I just want the script to pause before two minutes is up...then start again where it left off..hopefully, restarting it's max_execution_time. I don't know if sleep() can do that - sleep may count toward execution time, not sure.

The manual way was increasing the $count variable by 10 and then increasing the i$ in the while loop by 10 as well. Therefore it would start where it left off, doing 10 folders at a time. Refresh to run it. At the moment I have no cron access, either.

Here's the script...

    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>';

        }
    }
