Imagick::getResourceLimit

(PECL imagick 2, PECL imagick 3)

Imagick::getResourceLimitRetourne la limite de la ressource

Description

public static Imagick::getResourceLimit(int $type): int

Retourne la limite de la ressource.

Liste de paramètres

type

L'une des constantes de type de ressources.

Valeurs de retour

Retourne la limite de ressource spécifiée. L'unité dépend du type de ressource qui est limitée.

Erreurs / Exceptions

Lance une exception ImagickException si une erreur survient.

Voir aussi

add a note

User Contributed Notes 1 note

up
0
holdoffhunger at gmail dot com
12 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 :

<?php

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

$imagick_type->readImageFile($file_handle_for_viewing_image_file);

// Get/Display Resource Values
// ---------------------------------------------

print("Undefined: ");
print(
$imagick_type->getResourceLimit(imagick::RESOURCETYPE_UNDEFINED));

print(
"<br><br>Area: ");
print(
$imagick_type->getResourceLimit(imagick::RESOURCETYPE_AREA));

print(
"<br><br>Disk: ");
print(
$imagick_type->getResourceLimit(imagick::RESOURCETYPE_DISK));

print(
"<br><br>File: ");
print(
$imagick_type->getResourceLimit(imagick::RESOURCETYPE_FILE));

print(
"<br><br>Map: ");
print(
$imagick_type->getResourceLimit(imagick::RESOURCETYPE_MAP));

print(
"<br><br>Memory: ");
print(
$imagick_type->getResourceLimit(imagick::RESOURCETYPE_MEMORY));

?>
To Top