You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Andy Lester <an...@petdance.com> on 2002/02/27 19:00:26 UTC

Making perl handlers handle non-Perl

How can I get mod_perl to handle all Apache output, whether or not it
originates with mod_perl?

I'm writing a module that needs to analyze all output generated by Apache.
That's easy enough with stacked handlers, but I'm goofing something up
with, say, static HTML.

If I do this:

        <Location /test>
                PerlHandler     MyFilter
        </Location>

Then static HTML gets served up OK, but MyFilter doesn't seem to get
called.  Or is it, and I'm screwing something up in the filter?

And of course if I do this:

        <Location /test>
		SetHandler	perl-script
                PerlHandler     MyFilter
        </Location>

Then I get no output because the .html files that I'm trying to serve up
out of /test aren't Perl.

Pointers please?  I've got both the Cookbook and the Eagle book if you
want to just point to a page.

Thanks,
Andy


-- 
%_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
"hack";print map delete$_{$_},split//,q<   andy@petdance.com   >



RE: Apache stops serving requests

Posted by Jeremy Rusnak <jr...@igl.net>.
>While rebuilding perl and apache/modperl could possibly fix it, check your
>error log for segmentation faults.

No segfaults at all.  The last core file I've got on one of the affected
boxes is from early January.

Thanks,
Jeremy

Re: Apache stops serving requests

Posted by Tim Tompkins <ti...@arttoday.com>.
While rebuilding perl and apache/modperl could possibly fix it, check your
error log for segmentation faults.


Regards,

Tim Tompkins
----------------------------------------------
Programmer
http://www.arttoday.com/
http://www.rebelartist.com/
----------------------------------------------



RE: Apache stops serving requests

Posted by Jeremy Rusnak <jr...@igl.net>.
>Definitely go for 5.6.1 at least, 5.6.0 is buggy.  Compile your own,
>don't use RPMs unless you have evidence they'll be OK.  I use 5.7.2
>now in development and I'd be quite happy with to go live with it,
>although I don't do anything fancy in my Perl code if I can avoid it.

I'll give this a shot.

>I would stick with the compiler from 6.2, gcc has been having its own
>growing pains recently but I'll admit I'm not up to date with the
>present state of it.  The last time I looked, the latest gcc couldn't
>reliably compile the Linux kernel.

There are a series of patches that supposedly help with that problem,
but I agree.

>Nothing contentious there.  You doing anything with suexec?  Dunno why I
ask.

No, suexec is disabled.

>I have seen a couple of problems on 1.3.22. which seemed to be fixed by
upgrade
>to .23 but as I said, they didn't seem to bear any resemblance to your
trouble.

Maybe I will reroll everything up the latest version and see what happens.

>> I'm maintaining around 12 web servers which all have hiccups from
>> time to time.
>
>How often is "from time to time"?  I expect my servers to run quite
>literally for years without any hiccups at all.

Well about once a month or so one of the servers will need attention for
one reason or another.  We've got some relatively old hardware (SMP P2
400mhz
boxes) mixed in that we are pushing very hard...We've been replacing these
older midtowers with 1U rack mounts which helps.  Most of our boxes have
uptime of over a year, it's just that sometimes a MySQL table gets
corrupted here or there, a server gets a DOS attack, etc.

>Do you compile your own kernels?

Yes.  For the most part I compile everything we need right into the kernel
and disable loadable module support (dunno why, I've just always been
happier building it right in than using modules).  The only exception to
this are the newer 1U machines.  They are Penguin Computing boxes and
we're using the stock 2.4 kernels they came with (haven't had any
problems with those machines either).  I don't upgrade kernels that
often (if it isn't broken...) as I'm offsite and we've got just about
everything blocked out at the router except port 80.

Jeremy


RE: Apache stops serving requests

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi again,

On Thu, 28 Feb 2002, Jeremy Rusnak wrote:

> This has been happening on both 2.4 and 2.2 machines.  I've recompiled
> everything but Perl itself (5.6.0) with the stock Redhat 6.2 and 7.2

Definitely go for 5.6.1 at least, 5.6.0 is buggy.  Compile your own,
don't use RPMs unless you have evidence they'll be OK.  I use 5.7.2
now in development and I'd be quite happy with to go live with it,
although I don't do anything fancy in my Perl code if I can avoid it.

I would stick with the compiler from 6.2, gcc has been having its own
growing pains recently but I'll admit I'm not up to date with the
present state of it.  The last time I looked, the latest gcc couldn't
reliably compile the Linux kernel.

> I'm hoping someone will be able to say "this is the problem"

I haven't seen anything resembling this mentioned here on the mod_perl List.

> lose sleep over problems that "just go away."

Yep.

> Compiled-in modules:
> ...

Nothing contentious there.  You doing anything with suexec?  Dunno why I ask.

> I was thinking perhaps it could be something with 1.3.22, but
> since it isn't happening elsewhere I'm not positive.

I have seen a couple of problems on 1.3.22. which seemed to be fixed by upgrade
to .23 but as I said, they didn't seem to bear any resemblance to your trouble.

> I'm maintaining around 12 web servers which all have hiccups from
> time to time.

How often is "from time to time"?  I expect my servers to run quite
literally for years without any hiccups at all.

> The problem I have described definately happens
> on the mod_perl boxes once or twice a day.  The handful of problems
> on the other machines I'm of course starting to second guess and
> wonder about, but it's just paranoia.

I'm not so sure.  Just because you're paranoid it doesn't mean they
aren't all out to get you...

> Guess I should keep a more detailed log

Agreed.

Do you compile your own kernels?

73,
Ged.


RE: Apache stops serving requests

Posted by Jeremy Rusnak <jr...@igl.net>.
>Is this for example only on the machines running Linux 2.4, did you
>recompile everything including Perl, what compiler and compilation
>options did you use, are you using DSO, have you read the file
>mod_perl/SUPPORT, have you tried mod_perl-1.26_01 and/or
>apache_1.3.23...?

This has been happening on both 2.4 and 2.2 machines.  I've recompiled
everything but Perl itself (5.6.0) with the stock Redhat 6.2 and 7.2
compiler.  I have not tried 1.26_01 or apache 1.3.23 as of yet,
I'm hoping someone will be able to say "this is the problem" so
I can have a clear understanding of what has happened.  I sometimes
lose sleep over problems that "just go away."

I'm not using DSO, everything is compiled directly into httpd.

I apologize for not providing everything that one normally would
from the SUPPORT file.  I've been using mod_perl for two years now
and the "signature" from this one seemed so unique that if someone
else had run into it I'd find out right away.

Server version: Apache/1.3.22 (Unix)
Server built:   Jan 15 2002 18:57:13
Server's Module Magic Number: 19990320:10
Server compiled with....
 -D HAVE_MMAP
 -D HAVE_SHMGET
 -D USE_SHMGET_SCOREBOARD
 -D USE_MMAP_FILES
 -D HAVE_FCNTL_SERIALIZED_ACCEPT
 -D HAVE_SYSVSEM_SERIALIZED_ACCEPT
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D HTTPD_ROOT="/home/httpd"
 -D SUEXEC_BIN="/home/httpd/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_XFERLOG="logs/access_log"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
 -D ACCESS_CONFIG_FILE="conf/access.conf"
 -D RESOURCE_CONFIG_FILE="conf/srm.conf"

Compiled-in modules:
  http_core.c
  mod_env.c
  mod_log_config.c
  mod_mime.c
  mod_negotiation.c
  mod_include.c
  mod_autoindex.c
  mod_dir.c
  mod_cgi.c
  mod_alias.c
  mod_access.c
  mod_auth.c
  mod_setenvif.c
  mod_perl.c

>> We're running several other machines on Apache 1.3.22 and I've
>
>You mean you're running Apache 1.3.22 without mod_perl on several
>other machines?

That's correct.  I haven't noticed a similiar problem using 1.3.22
by itself or with PHP (which is used on several boxes as well).
I was thinking perhaps it could be something with 1.3.22, but
since it isn't happening elsewhere I'm not positive.

>> only really run into this problem on the mod_perl boxes.
>Is the word "really" of any significance here?

I'm maintaining around 12 web servers which all have hiccups from
time to time.  The problem I have described definately happens
on the mod_perl boxes once or twice a day.  The handful of problems
on the other machines I'm of course starting to second guess and
wonder about, but it's just paranoia.  Guess I should keep a more
detailed log for myself when servers have problems.

Thanks very much,
Jeremy

Re: Apache stops serving requests

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,

On Thu, 28 Feb 2002, Jeremy Rusnak wrote:

[snip,snip]
> We're using mod_perl 1.26 and Apache 1.3.22 on kernel 2.2 and 2.4 on
> a few machines.  We upgraded to Apache 1.3.22 several weeks ago
> At random times Apache stops serving requests.
> The last entry reported in the Apache error log is:
> [Wed Feb 27 21:01:00 2002] [error] (32)Broken pipe: accept: (client socket)

Hmmm.  Funny one.

> My web searches have come up empty!

Is this for example only on the machines running Linux 2.4, did you
recompile everything including Perl, what compiler and compilation
options did you use, are you using DSO, have you read the file
mod_perl/SUPPORT, have you tried mod_perl-1.26_01 and/or apache_1.3.23...?

> We're running several other machines on Apache 1.3.22 and I've

You mean you're running Apache 1.3.22 without mod_perl on several
other machines?

> only really run into this problem on the mod_perl boxes.

Is the word "really" of any significance here?

73,
Ged.


Apache stops serving requests

Posted by Jeremy Rusnak <jr...@igl.net>.
Hi all,

We're using mod_perl 1.26 and Apache 1.3.22 on kernel 2.2 and 2.4 on
a few machines.  We upgraded to Apache 1.3.22 several weeks ago and
have been experiencing some strange problems.

At random times Apache stops serving requests.  Trying to bring up
a request brings up a "server not found" error.  When I log in to
the box, however, Apache is running and all the processes are in
a sleep state.

There doesn't seem to be any relation between load or traffic level.
It's happened at peak times of day, in the middle of the night,
you name it.

The last entry reported in the Apache error log is:

[Wed Feb 27 21:01:00 2002] [error] (32)Broken pipe: accept:
(client socket)

If I do a kill -HUP requests start being served correctly
again.

We're running several other machines on Apache 1.3.22 and I've
only really run into this problem on the mod_perl boxes.  I'm
left scratching my head on this one, can anyone help?  My web
searches have come up empty!

Thanks for any input you might have!

Jeremy


Re: Making perl handlers handle non-Perl

Posted by Perrin Harkins <pe...@elem.com>.
Nico Erfurth wrote:
> your handler could tie the output-handle (is this possible?) and run a 
> subrequest.

Nope, not possible.  You can only do that for mod_perl requests.

- Perrin


Re: Making perl handlers handle non-Perl

Posted by Nico Erfurth <ni...@headlight.de>.
Andy Lester wrote:

> How can I get mod_perl to handle all Apache output, whether or not it
> originates with mod_perl?
> 
> I'm writing a module that needs to analyze all output generated by Apache.
> That's easy enough with stacked handlers, but I'm goofing something up
> with, say, static HTML.
> 
> If I do this:
> 
>         <Location /test>
>                 PerlHandler     MyFilter
>         </Location>
> 
> Then static HTML gets served up OK, but MyFilter doesn't seem to get
> called.  Or is it, and I'm screwing something up in the filter?
> 
> And of course if I do this:
> 
>         <Location /test>
> 		SetHandler	perl-script
>                 PerlHandler     MyFilter
>         </Location>
> 
> Then I get no output because the .html files that I'm trying to serve up
> out of /test aren't Perl.
> 
> Pointers please?  I've got both the Cookbook and the Eagle book if you
> want to just point to a page.


<Just an idea>

Jou could try to set a location handler for

<LocationMatch "/*">
   SetHandler perl-script
   PerlHandler My::HandleEverything
</LocationMatch>

your handler could tie the output-handle (is this possible?) and run a 
subrequest.

Now it could intercept the output (written to the handle) and do 
changes, or tidy it up, whatever you want......
And at least, it should return DECLINE, if it isn't the main-request

</Just an idea>

I'm not sure if this will work, because of the needed tie of the outputhandle and so on,

maybe anyone else can give a better statement ;)))


-- 
Mit freundlichen Grüßen
-----------------------------
Nico Erfurth
Headlight Housingfactory GmbH
Email: ne@headlight.de
-----------------------------




Re: Making perl handlers handle non-Perl

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Perrin Harkins wrote:
> 
> Andy Lester wrote:
> > I want my MyFilter to process EVERYTHING that Apache spits out, whether
> > with mod_perl, mod_php or just reading a .html file from the filesystem,
> > especially the mod_php stuff.
> 
> Assuming you mean you want to look at the generated content from
> non-mod_perl handlers and do something with it, apache doesn't work that
> way.  Apache 2.0 does, but that won't help you right now.  You might try
> using a proxy server setup to do this instead.

ah, yes.  right, you can't intercept the output of other content
handlers, like mod_php or mod_cgi.  you can get to stuff handled by
mod_perl via Apache::Filter, or stuff that would be handled by core
Apache by manipulating the resource on disk directly (using
$r->filename), but that's about it.  at least for 1.3 (though I've
always been curious how mod_gzip works with 1.3)

seems I had my brain in the wrong place - thanks Perrin.

--Geoff

Re: Making perl handlers handle non-Perl

Posted by Perrin Harkins <pe...@elem.com>.
Andy Lester wrote:
> So, my HTML::Lint checking is only going to work on output from the
> mod_perl chain.

If you aren't terribly concerned about performance, there are several 
Apache::Proxy modules which should be easy to modify to put your lint 
checking in.  Do a search for "proxy" on CPAN to see what's out there.

- Perrin


Re: Making perl handlers handle non-Perl

Posted by Andy Lester <an...@petdance.com>.
> Assuming you mean you want to look at the generated content from
> non-mod_perl handlers and do something with it, apache doesn't work that
> way.  Apache 2.0 does, but that won't help you right now.  You might try
> using a proxy server setup to do this instead.

THAT'S the answer I was looking for.  Not what I wnated, but at least it
answers my question. :-)

So, my HTML::Lint checking is only going to work on output from the
mod_perl chain.  I guess that's better than nothing, but I've got plenty
of PHP code that I'd like to filter thru it as well.

Thanks, all.

Andy

-- 
%_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
"hack";print map delete$_{$_},split//,q<   andy@petdance.com   >



Re: Making perl handlers handle non-Perl

Posted by Perrin Harkins <pe...@elem.com>.
Andy Lester wrote:
> I want my MyFilter to process EVERYTHING that Apache spits out, whether
> with mod_perl, mod_php or just reading a .html file from the filesystem,
> especially the mod_php stuff.

Assuming you mean you want to look at the generated content from 
non-mod_perl handlers and do something with it, apache doesn't work that 
way.  Apache 2.0 does, but that won't help you right now.  You might try 
using a proxy server setup to do this instead.

- Perrin


Re: Making perl handlers handle non-Perl

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Andy Lester wrote:
> 
> > ok, SetHandler sets a content handler for a given <Location> - it supersededs everything else.
> >
> > unlike with normal Apache, mod_perl needs two things in order for your handler to be called:
> > the content hander to be perl-script (for Apache) and the name of your handler with PerlHandler (for
> > mod_perl)
> 
> So what we're saying is that with static .html files, there's no way for
> me to get mod_perl to interject itself into Apache's chain?  Or PHP for
> that matter?

oh, no.

if you want to intercept absolutely _everything_ I suspect that 

SetHandler perl-script 

at the server level will do the trick (outside of any <Location> or
other container directive).  just make sure you have a 

PerlHandler My::Foo

somewhere to fill in the mod_perl part, since mod_perl needs both
directives to work.

typically, folks don't want to intercept all requests - it's generally
better to let Apache serve static files itself so that it handles
stuff like HTTP/1.1 conditional headers and the like.

> 
> I want my MyFilter to process EVERYTHING that Apache spits out, whether
> with mod_perl, mod_php or just reading a .html file from the filesystem,
> especially the mod_php stuff.
> 
> Should I be looking at one of the later phases (cleanup?) instead of
> content generation?

the content-generation phase should be fine.

HTH

--Geoff

Re: Making perl handlers handle non-Perl

Posted by Andy Lester <an...@petdance.com>.
> ok, SetHandler sets a content handler for a given <Location> - it supersededs everything else.
>
> unlike with normal Apache, mod_perl needs two things in order for your handler to be called:
> the content hander to be perl-script (for Apache) and the name of your handler with PerlHandler (for
> mod_perl)

So what we're saying is that with static .html files, there's no way for
me to get mod_perl to interject itself into Apache's chain?  Or PHP for
that matter?

I want my MyFilter to process EVERYTHING that Apache spits out, whether
with mod_perl, mod_php or just reading a .html file from the filesystem,
especially the mod_php stuff.

Should I be looking at one of the later phases (cleanup?) instead of
content generation?

Thanks,
Andy

-- 
%_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
"hack";print map delete$_{$_},split//,q<   andy@petdance.com   >



Re: Making perl handlers handle non-Perl

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Andy Lester wrote:
> 
> How can I get mod_perl to handle all Apache output, whether or not it
> originates with mod_perl?
> 
> I'm writing a module that needs to analyze all output generated by Apache.
> That's easy enough with stacked handlers, but I'm goofing something up
> with, say, static HTML.
> 
> If I do this:
> 
>         <Location /test>
>                 PerlHandler     MyFilter
>         </Location>
> 
> Then static HTML gets served up OK, but MyFilter doesn't seem to get
> called.  Or is it, and I'm screwing something up in the filter?
> 
> And of course if I do this:
> 
>         <Location /test>
>                 SetHandler      perl-script
>                 PerlHandler     MyFilter
>         </Location>
> 
> Then I get no output because the .html files that I'm trying to serve up
> out of /test aren't Perl.
> 
> Pointers please?  I've got both the Cookbook and the Eagle book if you
> want to just point to a page.
> 

ok, SetHandler sets a content handler for a given <Location> - it supersededs everything else.

unlike with normal Apache, mod_perl needs two things in order for your handler to be called:
the content hander to be perl-script (for Apache) and the name of your handler with PerlHandler (for
mod_perl)

you probably want to do something with AddHandler instead of SetHandler

AddHandler .pl perl-script

you can also use <Files> sections instead of <Location>

see the later part of Recipe 14.2 gets into this somewhat.  Apache::MIMEMapper might also be of help
since, among other things, integrates with Apache::Filter easily...

HTH

--Geoff

Re: Making perl handlers handle non-Perl

Posted by Slava Bizyayev <sb...@outlook.net>.
As far as I understand, it should be a chain of handlers. It's very close to
one of my current projects. You have to serve one of the early stages of the
request to decide what handler is appropriate for the content generation
phase in particular conditions, and dynamically install that handler, which
in fact should be a kind of content filter...

Best regards,
Slava Bizyayev

----- Original Message -----
From: "Andy Lester" <an...@petdance.com>
To: <mo...@apache.org>
Sent: Wednesday, February 27, 2002 12:00 PM
Subject: Making perl handlers handle non-Perl


>
> How can I get mod_perl to handle all Apache output, whether or not it
> originates with mod_perl?
>
> I'm writing a module that needs to analyze all output generated by Apache.
> That's easy enough with stacked handlers, but I'm goofing something up
> with, say, static HTML.
>
> If I do this:
>
>         <Location /test>
>                 PerlHandler     MyFilter
>         </Location>
>
> Then static HTML gets served up OK, but MyFilter doesn't seem to get
> called.  Or is it, and I'm screwing something up in the filter?
>
> And of course if I do this:
>
>         <Location /test>
> SetHandler perl-script
>                 PerlHandler     MyFilter
>         </Location>
>
> Then I get no output because the .html files that I'm trying to serve up
> out of /test aren't Perl.
>
> Pointers please?  I've got both the Cookbook and the Eagle book if you
> want to just point to a page.
>
> Thanks,
> Andy
>
>
> --
> %_=split/;/,".;;n;u;e;ot;t;her;c; ".   #   Andy Lester
> 'Perl ;@; a;a;j;m;er;y;t;p;n;d;s;o;'.  #   http://petdance.com
> "hack";print map delete$_{$_},split//,q<   andy@petdance.com   >
>
>
>