©
Ce document utilise Manuel du site Web PHP chinois Libérer
(PECL imagick 2.0.0)
Imagick::getResourceLimit — Returns the specified resource limit
$type
)Returns the specified resource limit.
type
Refer to the list of resourcetype constants.
Returns the specified resource limit in megabytes.
错误时抛出 ImagickException。
[#1] holdoffhunger at gmail dot com [2012-05-23 23:43:48]
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));
?>