Page 1 of 1

ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-05T05:03:16-07:00
by Alasdair
Hi there,

I've been running some very memory and processing intensive scripts, calling ImageMagick through both the PHP imagick function and also directly using the exec function (which is a direct execution of ImageMagick). Both these methods are necessary for what I'm trying to do. I'm actually creating several thousand 12" CMYK images at 300dpi, if you want to know.

Anyway, the script was working perfectly for a while, but ImageMagick has recently stopped responding. Interestingly it still works fine using imagick through PHP, but the direct calls using the exec function no longer work at all. Even simple calls no longer work. Nothing happens. Also, ImageMagick returns no error. I've tried restarting the server, this helped at first, but then the problem quickly occurred again. Now when I restart the server the problem still occurs.

I thought this was probably a memory problem, because of the way it was happening. I have 4GB of RAM on my server, so I increased the max memory on both the PHP script and ImageMagick configuration file to 2GB. No difference, the problem is still there.

This is not because I have changed anything on the server, and ImageMagick is correctly installed. It was all working perfectly before it just went wrong.

This must be something to do with memory or temporary files.

Please someone help!

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-05T06:28:15-07:00
by magick
First add -limit area 1 to your command line to reduce memory requirements. If that fails, add -debug all to trace where the process is hanging.

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-06T00:50:36-07:00
by Alasdair
OK. So here's an update:

I added "-limit area 1" and "-cache 1" to the script, I restarted the server again, then restarted Apache again... and it started working again! It works for a few hours and then stopped again. I thought that it was the restart that fixed it, so I made a script that would restart Apache every time the error occurred, but it turns out that the restart makes no difference.

The only thing that seems to fix the problem is time. After ImageMagick stops working, it will start working again after a few hours.

This must be to do with the fact I'm processing very large images (>50MB).

I've now added "-debug all", however I don't understand how to use this feature. It does not return anything... where is the log recorded?

Thanks,
Alasdair

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-06T02:15:53-07:00
by Alasdair
"-debug all" seems to do nothing.

Here is an example:

Code: Select all

<?php

$titlefont='smallcaps.otf';
$title='This is a Test Title';
$cmd='convert -cache 1 -debug all -limit area 1 -colorspace CMYK -background transparent -font '.$titlefont.' -size 1335x'.(505+$plus).' -gravity center -fill "rgb(28,22,17)" caption:"'.$title.'" -trim working.png';
exec($cmd,$output,$return);
echo $return."\n\n";
echo implode("\n > ",$output);

?>
The above outputs only:

Code: Select all

0


Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-06T02:21:09-07:00
by Alasdair
And in case you're thinking along these lines:

Code: Select all

<?php

$cmd='convert -version';
exec($cmd,$output,$return);
echo $return."\n\n";
echo implode("\n > ",$output);

?>
Outputs:

Code: Select all

0

Version: ImageMagick 6.5.3-2 2009-06-04 Q16 OpenMP http://www.imagemagick.org
 > Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
 > 

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-06T02:54:15-07:00
by Bonzo
I have no idea where the -debug info goes; I assume you would need to direct it into a text file.

Anyway this should give you some more information on the errors:

Code: Select all

<?php
$array=array();
echo "<pre>";
exec("convert input.jpg output.jpg 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
?> 

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-06-06T04:17:32-07:00
by Alasdair
Wow... I've figured out what the problem was.

It wasn't an ImageMagick problem at all. It's just that I when I run the script from a cron job then it doesn't work, and when I run from the browser then it does work! So it must just be to do with directories or permissions or something along those lines.

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-07-10T10:48:14-07:00
by sabater_wb
Hello.

Please, someone help me.
The same problem occured in my server.
I rebooted it but imagemagick is not working yet.

I can run it thru ssh, but when I call it thru exec nothing happen.
-----

Re: ImageMagick Not Responding - Memory Problem?

Posted: 2009-07-10T11:17:58-07:00
by sabater_wb
I found the problem.

I don't know what happened, but now, I need to put the full path to convert.