(PECL imagick 2.0.0)

Imagick::getResourceLimitReturns the specified resource limit


int Imagick::getResourceLimit ( int $type )

Returns the specified resource limit.

Elenco dei parametri


Refer to the list of resourcetype constants.

Valori restituiti

Returns the specified resource limit in megabytes.


Lancia una ImagickException in caso di errore.

add a note add a note

User Contributed Notes 1 note

holdoffhunger at gmail dot com
2 years ago
By using the PHP function getResourceLimit, you'll be given the maximum allowed amount of a particular type of resource.  The integer returned is the number of bytes allowed to the resource you specified in the input parameter.  For the input parameter options, you have the predefined ResourceType constants for the ImageMagick package.  In the code, they look like imagick::RESOURCETYPE_AREA, but you have "_VALUE" options of: undefined, area, disk, file, map, and memory.

What do each of these particular values represent?  The ImageMagick official documentation is helpful in that matter.  File indicates "maximum number of open pixel cache files", Area indicates "maximum area in bytes of any one image that can reside in the pixel cache memory", Memory indicates "maximum amount of memory in bytes to allocate for the pixel cache", map indicates "maximum amount of memory map in bytes to allocate for the pixel cache", and disk indicates "maximum amount of disk space in bytes permitted for use by the pixel cache".  This is according to the Official ImageMagick Architecture page: http://www.imagemagick.org/script/architecture.php .

The Official ImageMagick Resource page has more information on how these parameters function.  For instance, the files limit documentation mentions that when a user goes over the limit, any more files will be "cached to disk are closed and reopened on demand."  (Again, a performance hit.)  See that page here: http://www.imagemagick.org/script/resources.php .

What happens when someone exceeds their limit?  It doesn't cause the PHP script to error out, but simply, it relocates their user activity to non-cache memory (i.e.: virtual memory, which is slow).  So, even if you're worried about the limit, it really only indicates the point in a server at which a user's request is devalued compared to other user requests.

And remember, you can always set the defaults in the policy.xml file on your own server.

Some sample code :


// Author: holdoffhunger@gmail.com
        // Imagick Type
        // ---------------------------------------------

$imagick_type = new Imagick();
// Open File
        // ---------------------------------------------
$file_to_grab = "image_workshop_directory/test.gif";
$file_handle_for_viewing_image_file = fopen($file_to_grab, 'a+');
// Grab File
        // ---------------------------------------------

// Get/Display Resource Values
        // ---------------------------------------------
print("Undefined: ");

"<br><br>Area: ");
"<br><br>Disk: ");
"<br><br>File: ");
"<br><br>Map: ");
"<br><br>Memory: ");

To Top