Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:57:33+00:00 2026-06-12T22:57:33+00:00

I have to render something with Imagick on PHP CLI. I have noticed that

  • 0

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.

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);

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

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

image of the memory consumption

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:57:34+00:00Added an answer on June 12, 2026 at 10:57 pm

    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.

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

    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);
    

    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.

    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()).

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


    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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a cshtml partial view (Razor engine) that is used to render something
I have a View that renders something like this: Item 1 and Item 2
I have seen metal/plastic/water/fire/... shaders for OpenGL. However, it it possible to render something
I would like to have AppEngine render an html page that auto scrolls to
I have a few partial views that should render when the user has a
I have a large database of XHTML that I wish to render as PDFs
I have a little problem understanding what an expression like {{ something.render() | safe
For example, I have something like this in my controller: def save ... render
So in my base template, I have: {% render EcsCrmBundle:Module:checkClock %} Then I created
I have to render some text to a web page. The text is coming

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.