Modperl and Imagemagick

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
tbraber

Modperl and Imagemagick

Post by tbraber »

A while ago I Posted a message on the Imagemagick Bugs mailing list about problems with ImageMagick 6.2.9 and later in combination width Modperl2 on Windows. I didn’t got any reactions. THis could mean a view things:
- it is a ‘my situation only’ problem and I made a mistake somewhere
- I posted in the wrong place
- There is no solution ??

But what I found out is that I couldn’t get any Imagemagick with version 6.2.9 and later to work on Windows 2003 or XP ( in combination width modperl2 and apache2).

My system is a standard Apache2.2.4 ( I also tried with earlier versions ) Modperl 2.03 ,Activestate perl 5.8.8.820.

At the moment Apache preloads the Image::Magick module, Apache crashes or exits immediately . On some machines without any error message on others with the error: ‘Unknown software exception ( 0x00000fd)’.

With ImageMagick 6.2.8 and earlier version it works fine.

Can anyone confirm that he successfully runs Image:Magick 6.3.x with modperl2 on a windows platform ( XP or 2003 ).
I also tried to use the perlMagick from version 6.2.8 and used this in combination with the 6.3.4 dll's but that didn't change a thing.

Does anyone has a clue?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Modperl and Imagemagick

Post by magick »

ImageMagick 6.3.4-5 is scheduled for release this weekend. It has a patch which looks likely will fix the problem you reported. Give it a try and let us know.
tbraber

Re: Modperl and Imagemagick

Post by tbraber »

I tried the 6.3.4-5 8 bit and 16 bit both on windows 2003 server and on XP-sp2 with no difference than the previous version. I also changed use Image::Magick; in require "Image/Magick.pm"; this only delayed the problem a seconds.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Modperl and Imagemagick

Post by magick »

To fix the problem we need either a stack trace or detailed instructions on setting up mod-perl under Windows so we can reproduce the crash.
tbraber

Re: Modperl and Imagemagick

Post by tbraber »

Here is a installation quickstart:

Installation for modperl on Windows XP or 2003

Requirements:

Apache 2.2.4 from http://httpd.apache.org/download.cgi
Activestate Perl 5.8.8 build 820 from http://www.activestate.com
Modperl2 2.03 from http://theoryx5.uwinnipeg.ca/ppms

Installation of modperl:

run the folowing command:

ppm install http://theoryx5.uwinnipeg.ca/ppms/mod_perl.ppd


Make a test directory at:

c:\modperl


Adding modperl config to apache:

add this line at the end of the module load section in de httpd.conf file:

LoadModule perl_module modules/mod_perl.so

add the following line to the end of the httpd.conf file ( apache2.2\conf\httpd.conf ):

Include c:\modperl\modperl.conf


Save the following files to a file called c:\modperl\modperl.conf

Code: Select all

PerlRequire "c:/modperl/perlstart.pl"

<Location /modtest>
	SetHandler perl-script
	PerlResponseHandler mymagick
</Location>

Save the following lines to a file called c:\modperl\perlstart.pl

Code: Select all

use strict;

print "Starting Modperl\t\t";

#----------------------------------------
# Enable the mod_perl environment.
#----------------------------------------
# preload all mp2 modules

use ModPerl::Util ();
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();
use Apache2::ServerRec ();
use Apache2::ServerUtil ();
use Apache2::Connection ();
use Apache2::Log ();
use Apache2::Const -compile => ':common';
use APR::Const -compile => ':common';
use APR::Table ();
use Apache2::Response;
use Apache2::URI ();
use ModPerl::Const qw( EXIT );

print "[  OK  ]\n";

print "Preloading modules\t\t";

use Image::Magick();
use lib "c:/modperl";

print "[  OK  ]\n";
1;

Save the following lines to a file called c:\modperl\mymagick.pm

Code: Select all

package mymagick;
use strict;
use Apache2::RequestRec ();  # for $r->content_type
use Apache2::RequestIO ();
use Apache2::Const -compile => ':common';
use Image::Magick;

sub handler {
    my $r = shift;
    my $time = scalar localtime();
    my $package = __PACKAGE__;
    $r->content_type('text/html');
    print <<HTML;
<html>
<body>
This is a Image-Magick test script
</body>
</html>
HTML

    return Apache2::Const::OK;
}
1;

Restart Apache and try in your browser: http://localhost/modtest

THis should show:

'This is a Image-Magick test script'

In your browser
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Modperl and Imagemagick

Post by magick »

Thanks to your detailed instructions for installing modperl we were able to reproduce the problem you posted. We have a solution but will need a few days to test it. Look for a patch in ImageMagick 6.3.4-6 Beta by the weekend at the latest.
tbraber

Re: Modperl and Imagemagick

Post by tbraber »

Great !! :D

I tried version 6.3.4-9 -Q8 dll and it works now under Modperl. I did some quick testing and it looks like everything is working ok.

Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Modperl and Imagemagick

Post by magick »

The problem was we changed from an iterative to a recursive method for parsing the messaging configuration file. Unfortunately we allocated the message buffer on the stack which worked fine from the command line but failed with the more constrained stack under modperl. The fix was simply to allocate the message buffer from the heap.
User avatar
Randolf
Posts: 19
Joined: 2007-10-08T20:58:27-07:00
Location: Beautiful British Columbia, Canada

Re: Modperl and Imagemagick

Post by Randolf »

Could you check the code again with the current release? I'm experiencing intermittent startup problems on a test machine where Apache HTTPd server just crashes at startup only when ImageMagick is included in the configuration (I will be testing on NetBSD Unix shortly, but I doubt there will be any problems there). If I click on "Start" in the Apache Monitor a few times, it eventually does succeed, but the number of attempts is inconsistent. I didn't experience this problem with Apache HTTPd v2.0.x and a slightly older version of Perl and ImageMagick (libapreq2 is used heavily in all new projects, which prompted the upgrade to Apache HTTPd v2.2).

ImageMagick v6.3.5-10 Q16 (dynamic/DLL version)
ActiveState Perl v5.8.8 build 822
Apache HTTPd v2.2.6
Apache libapreq2 v2.08
ModPerl v2.0.3
Apache-DBI v1.06
DBI v1.58
DBD::Pg v1.49
Windows XP Home (with SP2)

I've also discovered that including the following in "httpd.conf" increases the success rate for starting HTTPd (I didn't need to use the "LoadFile" directive with Apache HTTPd v2.0.x and the slightly older versions of Perl and ImageMagick):

LoadFile "C:/Perl/site/lib/auto/Image/Magick/Magick.dll"
PerlModule Image::Magick

ImageMagick was installed after Perl, and was installed with the option to integrate into ActiveState Perl. Previous versions of Perl, ImageMagick, and Apache HTTPd server were all uninstalled (and the system rebooted) prior to installing the new versions.

Thanks in advance.

Randolf Richardson - randolf@richardson.tw
Greater Vancouver, British Columbia, Canada
Randolf Richardson - randolf@richardson.tw
Greater Vancouver Area, Beautiful British Columbia, Canada

"Petition to make all spam illegal in Canada:"
http://www.lumbercartel.ca/law/canada/s-220/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Modperl and Imagemagick

Post by magick »

Several releases ago, as part of our regression testing before a release, we check to ensure ImageMagick/PerlMagick runs under Apache Mod Perl. We will try updating to the release levels you mention to see if we can reproduce the problem. It may be several days before we report back.
User avatar
Randolf
Posts: 19
Joined: 2007-10-08T20:58:27-07:00
Location: Beautiful British Columbia, Canada

Re: Modperl and Imagemagick

Post by Randolf »

Wow! I wasn't expecting such a quick reply (I noticed as I checked some other topics in case I could provide some help to others) -- thanks!

I also just realized that there's a slightly newer version of ImageMagick available now, and so I'll give that a try as well and post back here if it seems to make a difference after restarting Apache a few dozen times.

Regarding regression testing, please make sure you include libapreq2 in the tested environment (think of libapreq2 as the modern replacement for the ancient CGI module and all its successors).

Randolf Richardson - randolf@richardson.tw
Greater Vancouver, British Columbia, Canada
Randolf Richardson - randolf@richardson.tw
Greater Vancouver Area, Beautiful British Columbia, Canada

"Petition to make all spam illegal in Canada:"
http://www.lumbercartel.ca/law/canada/s-220/
User avatar
Randolf
Posts: 19
Joined: 2007-10-08T20:58:27-07:00
Location: Beautiful British Columbia, Canada

Re: Modperl and Imagemagick

Post by Randolf »

The new version of ImageMagick (ImageMagick-6.3.5-10-Q16-windows-dll.exe) seems to be faster at load/unload time. I also don't need to use the LoadFile directive with this version. These are two excellent benefits, obviously, and I'm pleased to have them.

There seems to be a problem with Apache HTTPd server taking a long time to shut down (indicated by delayed removal of the "httpd.pid" file; normally "C:/Program Files/Apache Software Foundation/Apache2.2/logs/httpd.pid" with a default installation on Windows XP) when ImageMagick is pre-loaded by ModPerl (see code below), especially if I use the "Restart" option from the Apache Monitor convenience application.

What I have to do is make sure that the "httpd.pid" file has been deleted before starting the web server software in order to get it to start successfully. So, this newer version of ImageMagick seems to have resulted in Apache HTTPd server not crashing at startup now (even when it does fail to start), which is a great improvement indeed.

One addition consideration for regression testing for you is that I use the PerlModule directive from within a VirtualHost container (using name-based virtual hosting), like so:

Code: Select all

<VirtualHost *:80>
  ServerName lumbercartel.ca
  ServerAlias www.lumbercartel.ca
  PerlModule Image::Magick
</VirtualHost>
There are other directives used for specifying log files path, document root, server admin., etc., but I omitted them because they're typical configuration options that I think aren't relevant.

I hope this is helpful to you. Thanks again for your help.
Randolf Richardson - randolf@richardson.tw
Greater Vancouver Area, Beautiful British Columbia, Canada

"Petition to make all spam illegal in Canada:"
http://www.lumbercartel.ca/law/canada/s-220/
tbraber

Re: Modperl and Imagemagick

Post by tbraber »

It seems that there is a problem with apache 2.26 and Modperl 2.03 ( see modperl mailing list ) so it is better not to use this until the next release of Apache comes out ( use 2.24 at the moment, that works fine ).

There is also a problem with the combination ActiveState Perl v5.8.8 build 822
and the modperl 2.03 from theoryx5.uwinnipeg.ca.
( see modperl maling list also )
This all makes it hard test the lates imagemagick because it does not work with Activestate 5.8.8 build 820.

I hope the ActiveState Perl v5.8.8 build 822 problems will be fixed soon, then I can test the latest Imagemagick again.

What I can do is test it with Vista, because the Activestate problem wasn't found there.

I will keep you informed.

------

Thomas den Braber
User avatar
Randolf
Posts: 19
Joined: 2007-10-08T20:58:27-07:00
Location: Beautiful British Columbia, Canada

Re: Modperl and Imagemagick

Post by Randolf »

Okay, here's an update: Under NetBSD 4.0_RC3, running Apache HTTPd v2.2.6 with ModPerl v2.0.3, libapreq2 v2.0.8, and Perl v5.8.8.

If I use the "PerlModule Image::Magick" directive in my httpd.conf file, I get a core dump (of httpd, not the OS). I can, however, get it to work if I use "use Image::Magick;" in my .pm or .pl files.

So, I have a work-around for now that works very well, and will hopefully bring this issue down to lower priority. Eventually, however, if there is a benefit of using the PerlModule directive in httpd.conf, I'd definitely like to see this fixed. Thanks in advance.
Randolf Richardson - randolf@richardson.tw
Greater Vancouver Area, Beautiful British Columbia, Canada

"Petition to make all spam illegal in Canada:"
http://www.lumbercartel.ca/law/canada/s-220/
webminster

Re: Modperl and Imagemagick

Post by webminster »

I do not have an apparent problem with core dumps or similar, I simply cannot get any errors or returned results from PerlMagick, with the releases (6.2.8 or above) that I've tried.

I need to upgrade to the 6.3 series, preferably 6.3.7. Unfortunately we have code running under mod_perl (tried 2.0.2 and 2.0.3) and Apache 2.2.4, that with the PerlMagick upgrade, simply stops working. The Ping method returns undef, given a good image that command-line identify runs well.

The part that is making this very hard to debug is, the same code sequence, running as a Perl script outside of mod_perl, works fine.

Does anyone know of issues with the Ping method under mod_perl (running on CentOS4)? Are there any pointers to how to debug problems like this? Colleague and I are pretty stumped why the upgrade kills Ping. Thanks in advance for any suggestions.
-Alan
Post Reply