For While Loop Script pause/restart to run under max_execution_time
<p>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.</p>

<p>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.</p>

<p>Here's the script...</p>

<pre><code>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&lt;br&gt;';

//Loop through all 1000 folders 0 to 999 in the /full dir
for($i=0; $i &lt; $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 != "." &amp;&amp; $entry != ".." &amp;&amp;        !is_dir($entry)) {
          $img = new GImage($source.'/'.$i.'/'.$entry);

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

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

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

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

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

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

                 //echo $entry.'&lt;br&gt;';
        }

            }

        echo 'Processed: '.$i.' Folder&lt;br&gt;';

    }
}
</code></pre>
