1. <i id='4QFHu'><tr id='4QFHu'><dt id='4QFHu'><q id='4QFHu'><span id='4QFHu'><b id='4QFHu'><form id='4QFHu'><ins id='4QFHu'></ins><ul id='4QFHu'></ul><sub id='4QFHu'></sub></form><legend id='4QFHu'></legend><bdo id='4QFHu'><pre id='4QFHu'><center id='4QFHu'></center></pre></bdo></b><th id='4QFHu'></th></span></q></dt></tr></i><div id='4QFHu'><tfoot id='4QFHu'></tfoot><dl id='4QFHu'><fieldset id='4QFHu'></fieldset></dl></div>
      1. <small id='4QFHu'></small><noframes id='4QFHu'>

        <legend id='4QFHu'><style id='4QFHu'><dir id='4QFHu'><q id='4QFHu'></q></dir></style></legend>
        <tfoot id='4QFHu'></tfoot>
          <bdo id='4QFHu'></bdo><ul id='4QFHu'></ul>

        PHP Imagick 内存泄漏

        PHP Imagick memory leak(PHP Imagick 内存泄漏)

            • <bdo id='X5QTg'></bdo><ul id='X5QTg'></ul>
                <tbody id='X5QTg'></tbody>
              <i id='X5QTg'><tr id='X5QTg'><dt id='X5QTg'><q id='X5QTg'><span id='X5QTg'><b id='X5QTg'><form id='X5QTg'><ins id='X5QTg'></ins><ul id='X5QTg'></ul><sub id='X5QTg'></sub></form><legend id='X5QTg'></legend><bdo id='X5QTg'><pre id='X5QTg'><center id='X5QTg'></center></pre></bdo></b><th id='X5QTg'></th></span></q></dt></tr></i><div id='X5QTg'><tfoot id='X5QTg'></tfoot><dl id='X5QTg'><fieldset id='X5QTg'></fieldset></dl></div>
              <legend id='X5QTg'><style id='X5QTg'><dir id='X5QTg'><q id='X5QTg'></q></dir></style></legend>
                <tfoot id='X5QTg'></tfoot>

                <small id='X5QTg'></small><noframes id='X5QTg'>

                  本文介绍了PHP Imagick 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我必须在 PHP CLI 上用 Imagick 渲染一些东西.我注意到每 3-5 天服务器内存就会满,所以我什至无法通过 ssh 或 ftp 连接.

                  I have to render something with Imagick on PHP CLI. I have noticed that every 3-5 days the server memory gets full, so i can't even connet via ssh or ftp.

                  使用 memory_get_usage() 我将内存泄漏缩小到脚本的 imagick 部分.脚本看起来像这样:

                  with memory_get_usage() i narrwoed the memory leak down to the imagick part of the script. the script looks something like this:

                  $sourceImg = 'source.png';
                  $destImg = 'dest.png';
                  $background ='#00ff00';
                  
                  $im = new Imagick();
                  $im->pingImage($sourceImg);
                  $im->readImage($sourceImg); 
                  $draw = new ImagickDraw();
                  
                  for($i=1;$i<=5;$i++){
                      $draw->setFillColor( $background);
                      $draw->rectangle( 10*$i+5, 10, 10*$i+10, 20);
                  } 
                  
                  $im->drawImage( $draw );
                  $im->writeImage( $destImg );
                  $im->destroy();
                  
                  unset($im,$draw);
                  

                  我销毁了图像引用,并取消了 imagick 和 imagickDraw 对象的设置,但脚本不会释放任何内存.setFillColor() 方法占用的内存最多

                  I destroy the image reference, and unset the imagick and imagickDraw object, but the script won't release any memory. The setFillColor() method takes the most memory

                  我可以做些什么来释放 imageick 使用的空间吗?

                  Can i do something else to free the space used by imageick?

                  内存消耗图片

                  推荐答案

                  imagick 使用共享库,它的内存使用量对于 PHP 来说是遥不可及的,因此调整 PHP 内存和垃圾收集无济于事.

                  imagick uses a shared library and it's memory usage is out of reach for PHP, so tuning PHP memory and garbage collection won't help.

                  我自己也遇到了同样的问题,试图处理 50 (!) 页 3000x2000 像素的多页 tiff 图像.解决方案是让 imagick 将其像素缓存放在磁盘上.

                  I had the same problem myself, trying to handle a multi-page-tiff image with 50 (!) pages of 3000x2000 pixels. The solution is to have imagick put its pixel cache on disk.

                  在创建 Imagick 对象之前添加它为我解决了这个问题:

                  Adding this prior to creating the Imagick object solved the problem for me:

                  // pixel cache max size
                  IMagick::setResourceLimit(imagick::RESOURCETYPE_MEMORY, 256);
                  // maximum amount of memory map to allocate for the pixel cache
                  IMagick::setResourceLimit(imagick::RESOURCETYPE_MAP, 256);
                  

                  目标是让 imagick 将其像素缓存放在磁盘而不是 RAM 中.默认位置似乎是文件/tmp/magick-XXnnnnn,因此请确保/tmp 不在 shmfs/ramdisk 上,或者更改 imagick 使用的临时目录.

                  The goal is to make imagick put its pixel cache on disk instead of in RAM. The default place seems to be files /tmp/magick-XXnnnnn, so make sure /tmp is not on shmfs/ramdisk, or change the temp directory imagick uses.

                  要调查的其他资源限制:imagick::RESOURCETYPE_DISKimagick::RESOURCETYPE_FILEimagick::RESOURCETYPE_AREA.它们在 imagick::getResourceLimit() 手册页中有描述(在页面中不太好)对于 setResourceLimit()).

                  Other resouce limits to investigate: imagick::RESOURCETYPE_DISK, imagick::RESOURCETYPE_FILE, and imagick::RESOURCETYPE_AREA. They are described in the imagick::getResourceLimit() manual page (not so well in the page for setResourceLimit()).

                  在我的图像处理循环中,我有 set_time_limit(300),因为脚本需要很长时间来处理这个巨大的(解压缩时)图像.

                  In my image handling loop, I have set_time_limit(300), since the script takes ages to process this huge (when uncompress) image.


                  EDIT : 在最近的版本中,setResourceLimit() 不应作为静态方法调用,而是在实际对象上调用,例如:


                  EDIT : In recent versions, setResourceLimit() should not be called as a static method, but on the actual object instead, such as:

                  $im->setResourceLimit(imagick::RESOURCETYPE_MEMORY, 256);
                  $im->setResourceLimit(imagick::RESOURCETYPE_MAP, 256);
                  $im->setResourceLimit(imagick::RESOURCETYPE_AREA, 1512);
                  $im->setResourceLimit(imagick::RESOURCETYPE_FILE, 768);
                  $im->setResourceLimit(imagick::RESOURCETYPE_DISK, -1);
                  

                  这篇关于PHP Imagick 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <small id='oKWLO'></small><noframes id='oKWLO'>

                  • <legend id='oKWLO'><style id='oKWLO'><dir id='oKWLO'><q id='oKWLO'></q></dir></style></legend>

                    <i id='oKWLO'><tr id='oKWLO'><dt id='oKWLO'><q id='oKWLO'><span id='oKWLO'><b id='oKWLO'><form id='oKWLO'><ins id='oKWLO'></ins><ul id='oKWLO'></ul><sub id='oKWLO'></sub></form><legend id='oKWLO'></legend><bdo id='oKWLO'><pre id='oKWLO'><center id='oKWLO'></center></pre></bdo></b><th id='oKWLO'></th></span></q></dt></tr></i><div id='oKWLO'><tfoot id='oKWLO'></tfoot><dl id='oKWLO'><fieldset id='oKWLO'></fieldset></dl></div>

                  • <tfoot id='oKWLO'></tfoot>

                        <bdo id='oKWLO'></bdo><ul id='oKWLO'></ul>

                              <tbody id='oKWLO'></tbody>