duanjia8215 2010-01-22 22:58
浏览 373

限制IMagick中的线程数(PHP)

When using ImageMagick, I can set certain limits for memory usage and maximum number of threads. There are 3 ways to do this, as far as I know:

  1. use a command line options like "convert -limit memory 128mb original.jpg new.jpg"
  2. use environment variables like "MAGICK_THREAD_LIMIT=1"
  3. edit the 'policy.xml' configuration file to change the default value.

I have tested each of these methods using "convert -list resource" and they work.

Now, I need to use the IMagick extension in PHP. There is a function I can use to set limits:

bool Imagick::setResourceLimit (int $type, int $limit)

For the first parameter I can use one of the following:

imagick::RESOURCETYPE_AREA (integer)   //equivalent of MAGICK_AREA_LIMIT
imagick::RESOURCETYPE_DISK (integer)   //equivalent of MAGICK_DISK_LIMIT
imagick::RESOURCETYPE_FILE (integer)   //equivalent of MAGICK_FILE_LIMIT
imagick::RESOURCETYPE_MAP (integer)    //equivalent of MAGICK_MAP_LIMIT
imagick::RESOURCETYPE_MEMORY (integer) //equivalent of MAGICK_MEMORY_LIMIT

The problem is that there is no equivalent for MAGICK_THREAD_LIMIT and IMagick seems to simply ignore the configuration files and the environment variables. How do I know this? I've set all the memory limits to zero and IMagick still functions without any problem when it should report insufficient memory.

I really hope I have made myself clear. The question is: how can I change the thread limit when using IMagick?

EDIT: I've managed to set the thread limit to 1 by compiling ImageMagick with the '--without-threads' option. :P It will have to do until I find a better solution.

  • 写回答

4条回答 默认 最新

  • douba4275 2010-07-13 06:24
    关注

    There is no corresponding constant defined for the thread limit in the PHP IMagick extension, but looking at the source the integer value should be 6 so you could try that (see ResourceType in magick/resource_.h, the needed value is ThreadResource). Am using MagickWand for PHP and had the same issue--fix was to enable this constant and recompile. If you are interested in patching MagickWand for PHP 1.0.8 the fix is:

    magickwand_inc.h
    -#define PRV_IS_ResourceType( x ) (x == AreaResource || x == DiskResource || x == FileResource || x == MapResource || x == MemoryResource)  /* || x == UndefinedResource */
    +#define PRV_IS_ResourceType( x ) (x == AreaResource || x == DiskResource || x == FileResource || x == MapResource || x == MemoryResource || x == ThreadResource)  /* || x == UndefinedResource */
    
    magickwand.c
        MW_REGISTER_LONG_CONSTANT( MemoryResource );
    +   MW_REGISTER_LONG_CONSTANT( ThreadResource );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题