php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59031 Can't limit memory usage
Submitted: 2010-01-17 10:47 UTC Modified: 2010-01-28 07:02 UTC
From: showerheadsuk at hotmail dot com Assigned:
Status: Closed Package: imagick (PECL)
PHP Version: 5.3.0 OS: Ubuntu 9.10
Private report: No CVE-ID: None
 [2010-01-17 10:47 UTC] showerheadsuk at hotmail dot com
Description:
------------
When trying to limit the memory usage, it doesn't seem to have any effect.

I'm running php as cgi, and monitoring the php processes memory usage with the top command.

I've tried 
ImageMagick 6.5.4 with Imagick 2.3.0
ImageMagick 6.5.4 with Imagick 3.0.0b1
ImageMagick 6.5.9 with Imagick 3.0.0b1
But all produce the same results - massive memory usage when resizing large images.

I can limit memory usage when using ImageMagick on the commandline with the '-limit memory' and '-limit map' parameters, but the Imagick setResourceLimit function seems to have no effect.

Reproduce code:
---------------
    $thumb = new Imagick($originalImg);
    $thumb->setResourceLimit( Imagick::RESOURCETYPE_MEMORY, 64 );
    $thumb->setResourceLimit( imagick::RESOURCETYPE_MAP, 128 );
    $thumb->resizeImage(1024, 720, Imagick::FILTER_LANCZOS, 0.8, true);
    $thumb->destroy();

Expected result:
----------------
Memory usage stays below 128MB

Actual result:
--------------
Resizing 36.4MB jpeg (161MB uncompressed), the php process handling the script balloons to around 467MB (using the value from the RES column of top)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-27 15:17 UTC] mkoppanen@php.net
Can you try 3.0.0 and calling the method statically before creating an instance of the imagick class:

<?php
Imagick::setResourceLimit( Imagick::RESOURCETYPE_MEMORY, 64 );
....
 [2010-01-28 05:49 UTC] showerheadsuk at hotmail dot com
Calling the method statically just seems to make the php process handling the request die, I tried with both 3.0.0b1 and b2.
 [2010-01-28 07:02 UTC] mkoppanen@php.net
This bug has been fixed in SVN.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

should be fixed in svn now. reopen the issue if it persists. I would suggest taking a look at imagemagick policy configuration as well:

http://trac.imagemagick.org/browser/ImageMagick/trunk/config/policy.xml
 [2010-03-01 19:17 UTC] b at turbulent dot ca
I rested the issue described here and the proposed resolution using 3.0.0RC1 under PHP 5.3.0 and the problem is still apparent: the memory usage is not being limited even if  setResourceLimit( Imagick::RESOURCETYPE_MEMORY, 5) was invoked.

As described above, calling the function statically does not cause a crash anymore (this was properly fixed), but it does not limit the memory usage.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Feb 25 03:01:24 2021 UTC