Hi
I have a problem when using imagick for resizing images.
The imagick wrapper works correctly, but I detected that the server's RAM increases to the maximum available.
It looks like the method 'destroy', responsible for releasing the resources associated with object 'imagick' not release these resources.
My process resize a lot of images like a for loop, and in each iteration, the memory decrease slowly and steadily.
The only way to free the memory used is to make a restart apache.
The code i use is:
$image = "http://foto-cache.elcomercio.es/jpg/0/8 ... 932680.jpg";
$imagick = new Imagick();
$imagick->readImage($image);
$imagick->scaleImage(300, 300);
$imagick->clear();
$imagick->destroy();
you can try it by doing a loop 'for ($i = 1; $i <= 1000; $i++)' of this code and looking the decrease of server's RAM with a 'top -d 1'
thanks a lot
Destroy method doesn't free resources
Re: Destroy method doesn't free resources
Use unset($imagick) instead of $imagick->destroy(); The destroy() method destroys the image but not the object.
Re: Destroy method doesn't free resources
Hi
Using the method destroy memory was not released, so I use also the method unset, but it is the same, RAM memory continues decrease in each iteration.
To simulate concurrent requests (3 request per second during one minute), i use the 'apache jmeter' program.
I tried with this code in a test.php file.
$image = "http://foto-cache.elcomercio.es/jpg/0/8 ... 932680.jpg";
$imagick = new Imagick();
$imagick->readImage($image);
$imagick->scaleImage(300, 300);
header("Content-Type: image/jpg");
echo($imagick);
$imagick->clear();
$imagick->destroy();
unset($image);
unset($imagick);
exit();
Using the method destroy memory was not released, so I use also the method unset, but it is the same, RAM memory continues decrease in each iteration.
To simulate concurrent requests (3 request per second during one minute), i use the 'apache jmeter' program.
I tried with this code in a test.php file.
$image = "http://foto-cache.elcomercio.es/jpg/0/8 ... 932680.jpg";
$imagick = new Imagick();
$imagick->readImage($image);
$imagick->scaleImage(300, 300);
header("Content-Type: image/jpg");
echo($imagick);
$imagick->clear();
$imagick->destroy();
unset($image);
unset($imagick);
exit();
Re: Destroy method doesn't free resources
I think that readimage method have a large memory consumption, and this memory isn't free anytime.
Is this true???.
How can i free this used memory????
there is any alternative to resize a lot of images in memory without dicrease RAM memory????
thanks
Is this true???.
How can i free this used memory????
there is any alternative to resize a lot of images in memory without dicrease RAM memory????
thanks
Re: Destroy method doesn't free resources
The OS may not release some memory after its consumed and released. You may need to run a PHP garbage collection cycle. You can also set the memory limit to some low value. See http://www.imagemagick.org/script/resou ... nvironment MAGICK_MEMORY_LIMIT. You can set this as an environment variable or there is probably an Imagick method to set the memory limit. With a low memory limit, pixels are cached to disk which reduces memory consumption but slows down processing (disk I/O is slower than memory I/O).
Re: Destroy method doesn't free resources
hi again.
I tried to run a PHP garbage collection cycle, but, when i call the php method gc_collect_cycles(), it returns number of collected cycles equals to zero.
also, after i call to the garbage collector does not seem to free up memory.
I fixed the MAGICK_MEMORY_LIMIT environment variable to 100M, because i read that a image size of 5000x5000 needs a 80M to process it, and i have some images of this size.
If i reduce the MAGICK_MEMORY_LIMIT the memory consumption is more slow but finally if reaches the maximum of the memory.
I tried to run a PHP garbage collection cycle, but, when i call the php method gc_collect_cycles(), it returns number of collected cycles equals to zero.
also, after i call to the garbage collector does not seem to free up memory.
I fixed the MAGICK_MEMORY_LIMIT environment variable to 100M, because i read that a image size of 5000x5000 needs a 80M to process it, and i have some images of this size.
If i reduce the MAGICK_MEMORY_LIMIT the memory consumption is more slow but finally if reaches the maximum of the memory.