perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoffrey Young <ge...@modperlcookbook.org>
Subject Re: PerlCleanupHandler in modperl 2
Date Mon, 27 Mar 2006 17:55:40 GMT
we should keep this on-list :)

Clinton Gormley wrote:
>>it ought to work, but it should be setting a per-server cleanup instead of a
>>per-request cleanup.  see below.
>>
> 
> 
> Doh!

:)

> 
> 
> 
>>basically cleanups are performed when memory allocated for different parts
>>of the server lifecycle is destroyed.  so, httpd allocates memory for the
>>server, per-configuration, per-connection, and per-request.  setting up a
>>cleanup handler on each will run the handler whenever the memory pool goes
>>out of scope.
>>
> 
> 
> Ok - this starts to make sense.
> 
> What I'm trying to achieve is :
>  - a child init handler which turns on caching (so that the process 
>    is owned by the right user)
>  - a cleanup handler which cleans out the in memory cache at the end 
>    of each request
> 
> I seem to be having a lot of trouble putting them in the same place...

you should be able to put them both in the same place

package My::Foo;

use Apache2::ServerUtil;

Apache2::ServerUtil->server->add_config('PerlChildInitHandler My::init');
Apache2::ServerUtil->server->add_config('PerlCleanupHandler My::cleanup');

sub handler {
...

and provided you PerlModule your package it _should_ work...

> 
> In the config file :
> -------------------------------------------------------
> PerlRequire "/opt/apache/sites/obits/conf/startup.pl"
>  ## This doesn't work : 
> PerlChildInitHandler Obits::Dispatcher::activate_cache

it doesn't?  that's very odd.  if you can't do that then there's no reason
to have the PerlChildInitHandler, then, is there?

> 
> <Location / >
>     SetHandler perl-script
>     PerlResponseHandler Obits::Dispatcher
>     ## This does work :
>     PerlCleanupHandler Obits::Dispatcher::cleanup_cache
> --------------------------------------------------------
> 
> In the startup file:
> --------------------------------------------------------
> use Apache2::ServerUtil;
> # this works:
> Apache2::ServerUtil->server->push_handlers(
>    PerlChildInitHandler => \&activate_cache)
> --------------------------------------------------------
> 
> But from here, I can't push a cleanup handler that will be called for
> every request, can I?

via add_config() would be the way I would handle that.

> 
> I have it working by using the PerlChildInitHandler in the startup file
> and the PerlCleanupHandler in the apache config, but I would prefer to
> put both of these into the startup file.

using a startup file instead of the package should work, too.  see
t/response/TestAPI/add_config.pm for an example.

> 
> Is it possible? What am I missing?

just add_config() I think.

> 
> thanks for your response Geoff

:)

--Geoff

Mime
View raw message