You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matthew Hodgson <ma...@arasphere.net> on 2002/11/16 03:12:37 UTC

Executing Apache::Registry cached script from normal mod_perl

Hi,

I have a script which executes under Apache::Registry and resides in
/perl/blah.pl.  However, it only generates a fragment of a page, and is
normally embedded into an html template using SSI with something like:

<!--#perl sub="Apache::Include" arg="/perl/blah.pl" -->

I am very aware that this would be better implemented as a raw perl module
used from apache's startup.pl (and then embedded using something like
<!--#perl sub="Blah" -->) - but practically this isn't an option right
now.

My problem is that I would like to nonetheless execute this code from
'normal' mod_perl; from a library used from startup.pl.  I've tried doing
this two ways to date, both of which have failed painfully:

1) Apache::Include->virtual("/perl/blah.pl");

Which simply segfaults the httpd process - presumably because the perl
interpreter which tries to handle the Included request collides with the
one actually executing the original script.

2) Apache::ROOTwww_2edomain_2ecom::perl::blah_2epl();

Which fails with the above being an Undefined subroutine.  Now, running
this with apache in non-forking mode as httpd -X and
$Apache::Registry::Debug = 4, I first request the URL of /perl/blah.pl to
make sure that Apache::Registry has compiled and cached the script:

[Fri Nov 15 19:58:13 2002] [error] Apache::Registry::handler for
/www01/domain.com/perl/blah.pl in process 31030
[Fri Nov 15 19:58:13 2002] [error] Apache::Registry::handler examining
/perl/blah.pl
[Fri Nov 15 19:58:13 2002] [error] Apache::Registry::handler package
Apache::ROOTwww_2edomain_2ecom::perl::blah_2epl

And see that it seems to compile and cache the script fine, with the
expected name, and indeeds generates the output to the browser correctly.

However, on then requesting a different Apache::Registry script which
makes use of the library preloaded in startup.pl which attempts to execute
Apache::ROOTwww_2edomain_2ecom::perl::blah_2epl(), it still dies on
failing to find that subroutine.

Any insight into how I might persuade this to work (without doing the
Right Thing and shifting everything into preloaded libraries (and perhaps
handlers)) would be appreciated.

This is all happening under Apache/1.3.27 mod_perl/1.27, with
Apache::Registry version 2.01 running on debian woody x86.

thanks,

Matthew.


Re: Executing Apache::Registry cached script from normal mod_perl

Posted by Perrin Harkins <pe...@elem.com>.
Matthew Hodgson wrote:
> On Fri, 15 Nov 2002, Josh Chamas wrote:
> 
> 
>>Matthew Hodgson wrote:
>>
>>>Hi,
>>>
>>>I have a script which executes under Apache::Registry and resides in
>>>/perl/blah.pl.  However, it only generates a fragment of a page, and is
>>>normally embedded into an html template using SSI with something like:
>>>
>>><!--#perl sub="Apache::Include" arg="/perl/blah.pl" -->
>>>
>>>I am very aware that this would be better implemented as a raw perl module
>>>used from apache's startup.pl (and then embedded using something like
>>><!--#perl sub="Blah" -->) - but practically this isn't an option right
>>>now.
>>>
>>
>>How about just executing this file like this:
>>
>>   do "$path_to/perl/blah.pl";
>>
> 
> 
> I guess that just as long as the script is never actually executed under
> Apache::Registry, and if the only place it's ever do'd from is the plain
> library, then this is the best solution. :)  Presumably if I needed to
> execute blah.pl from many different libraries as well as actually embed it
> using <!--#perl sub="Apache::Include" -->, this wouldn't be so great as
> each instance of it would be compiled separately as part of that
> particular block of code, thus bloating the apache process horribly.

The other problem is that "do" will compile the script every time, even 
if it has been run before in that same process.  Slow.

You might want to look at how Apache::SSI does it.  You can copy the 
include handling code from there.  Otherwise, I would suggest copying 
some code from Apache::RegistryNG to compile it into a subroutine.

- Perrin


Re: Executing Apache::Registry cached script from normal mod_perl

Posted by Matthew Hodgson <ma...@arasphere.net>.
On Fri, 15 Nov 2002, Josh Chamas wrote:

> Matthew Hodgson wrote:
> > Hi,
> >
> > I have a script which executes under Apache::Registry and resides in
> > /perl/blah.pl.  However, it only generates a fragment of a page, and is
> > normally embedded into an html template using SSI with something like:
> >
> > <!--#perl sub="Apache::Include" arg="/perl/blah.pl" -->
> >
> > I am very aware that this would be better implemented as a raw perl module
> > used from apache's startup.pl (and then embedded using something like
> > <!--#perl sub="Blah" -->) - but practically this isn't an option right
> > now.
> >
>
> How about just executing this file like this:
>
>    do "$path_to/perl/blah.pl";
>

I guess that just as long as the script is never actually executed under
Apache::Registry, and if the only place it's ever do'd from is the plain
library, then this is the best solution. :)  Presumably if I needed to
execute blah.pl from many different libraries as well as actually embed it
using <!--#perl sub="Apache::Include" -->, this wouldn't be so great as
each instance of it would be compiled separately as part of that
particular block of code, thus bloating the apache process horribly.

As it happens, though, I think I can get away with only ever executing it
from one particular place. :)

thanks,

Matthew.



Re: Executing Apache::Registry cached script from normal mod_perl

Posted by Josh Chamas <jo...@chamas.com>.
Matthew Hodgson wrote:
> Hi,
> 
> I have a script which executes under Apache::Registry and resides in
> /perl/blah.pl.  However, it only generates a fragment of a page, and is
> normally embedded into an html template using SSI with something like:
> 
> <!--#perl sub="Apache::Include" arg="/perl/blah.pl" -->
> 
> I am very aware that this would be better implemented as a raw perl module
> used from apache's startup.pl (and then embedded using something like
> <!--#perl sub="Blah" -->) - but practically this isn't an option right
> now.
> 

How about just executing this file like this:

   do "$path_to/perl/blah.pl";

Regards,

Josh
________________________________________________________________
Josh Chamas, Founder                   phone:925-552-0128
Chamas Enterprises Inc.                http://www.chamas.com
NodeWorks Link Checking                http://www.nodeworks.com