Welcome Guest, Not a member yet? Register   Sign In
Problem resizing a lot of images with Image_Lib (5000 images)
#1

[eluser]Atas[/eluser]
I have a problem with Image_Lib.

The following code reads all the images from a folder (The folder path is ok). The folder has 5.000 images aprox. The code resizes each image to 6 different sizes.

Code:
$dir = dirname($_SERVER["SCRIPT_FILENAME"]).'/assets/images/products/temp/';

if (is_dir($dir)) {
  if ($gd = opendir($dir)) {
    while (($file = readdir($gd)) !== false) {
      if($file != "." and $file != ".." and !empty($file )){
    $this->images->resize_products_image($file );
    echo "[".date("y-m-d h:i:s")."] Resizing Image --&gt; ".$file ."<br>";
      }
    }
    closedir($gd);
   }
}

The problem is that the code processes 400, 500 images* (randomly) and then stops. I don't know the reason and no error message is shown.

*(The processed images are well processed)

I've checked max_execution_time and this is not causing the problem.

I've also put this piece of code at the beginning of the function:
Code:
error_reporting(E_ALL);
ini_set('display_errors',1);

Could this be a server issue?
Thanks,
#2

[eluser]hvalente13[/eluser]
Atas, do you really have to resize all images?

http://ellislab.com/forums/viewreply/430693/

Read this and say if it fits your needs?
#3

[eluser]marcoss[/eluser]
That's killing your server, process the images in blocks of 100 (you can try a higher number of course), have the app process a block, clean up, wait a second and move to the next block and you'll be done in less than a minute Wink
#4

[eluser]Atas[/eluser]
Hvalente13, thanks, but yes, I really need to resize all the images...

Marcoss, tomorrow i'll try processing the images in blocks, but it's strange it doesn't shows an "out of memory" error , or something like that...

Thanks both, i will post the results...
#5

[eluser]Atas[/eluser]
I've solved my problem
I followed Marco's tip and i divided the processes in parts. Every 20 images I do a redirect on the same url.

It is important to know that the images already resized are deleted from the temp directory. So when it does the redirect it doesn't parse them again.

It's probably a server problem, because when the image process crashes it creates a core.# file in the site root containing very strange info.

Thanks...
#6

[eluser]marcoss[/eluser]
Great! And regarding the need to delete the images to avoid duplicate processing, it's fine if they are in a temporary location and you don't need them any longer, otherwise you can choose to keep a log file/db with the images already processed and skip them once the page reloads.




Theme © iAndrew 2016 - Forum software by © MyBB