Re: Don't understand END blocks in mod_perl
by liz (Monsignor) on Sep 25, 2003 at 18:51 UTC
|
Assuming you're using mod_perl 1.X, check out docs about END blocks. Basically, END blocks are executed only when a child exits, not when a request is finished.
Also, check out your PERL_DESTRUCT_LEVEL environment variable setting. This may also affect whether END blocks are executed or not.
Hope this helps.
Liz | [reply] |
|
|
Yeah, I've read that (it's basically word-for-word what is in the Eagle book by Stein & MacEachern). It's possible that the PERL_DESTRUCT_LEVEL setting is what's preventing the END blocks from running where I think they should. I'll look into that.
| -- |
| Jeff Boes |
| Database Engineer |
| Nexcerpt, Inc. |
|
|
|
...Nexcerpt...Connecting People With Expertise
|
| [reply] [d/l] |
Re: Don't understand END blocks in mod_perl
by hardburn (Abbot) on Sep 25, 2003 at 17:43 UTC
|
Could you do it with DESTROY instead of __END__? (DESTORY being the method called when your object is garbage collected).
Update: Just remembered something--in mod_perl, your interpereter never exits until Apache goes down, which is why __END__ never gets called. So DESTROY with tight lexical scoping is really your only option here.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
Note: All code is untested, unless otherwise stated
| [reply] [d/l] [select] |
Re: Don't understand END blocks in mod_perl
by CountZero (Bishop) on Sep 26, 2003 at 06:23 UTC
|
Aha! The (in)famous, mod_perl does not run my 'END'-blocks matter. The canonical way of solving this problem is by either registering your own PerlCleanupHandler in the config-file of your Apache or by making a call to the register_cleanup method early in your script:
$r is your request object$r->register_cleanup(sub { ***your cleanup code here*** }); Your clean-up code then gets to run everytime your script finishes and not only when the child processing this request terminates. You could also take the easy way out and let your scripts run under Apache::Registry which let END-blocks run the way we are used to. CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [d/l] [select] |
|
|
(I seem to be having a tremendous amount of trouble getting my point across.)
I don't want the END blocks to run at script (request) end; I want them to run when the child exits.
I do have "PerlHandler Apache::Registry" in place, which should mean that the END blocks run when the child exits. They aren't, and I'm trying to figure out why.
| -- |
| Jeff Boes |
| Database Engineer |
| Nexcerpt, Inc. |
|
|
|
...Nexcerpt...Connecting People With Expertise
|
| [reply] [d/l] |
|
|
If you are running your script under Apache::Registry then your END-block will run when the script ends: Apache::Registry emulates the behaviour you see when running your scripts under (mod_)cgi. Quoting from Beckman & Cholet's "Practical mod_perl", p. 241: As you already know by now, Apache::Registry handles things differently. It does execute all END blocks encountered during compilation of Apache::Registry scripts at the end of each request, like mod_cgi does. That includes any END blocks defined in the packages use()d by the scripts. So if you want your END block to run at the child's exit only: don't use Apache::Registry or register your PerlChildExitHandler (Apache 2).CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |
Re: Don't understand END blocks in mod_perl
by perrin (Chancellor) on Sep 25, 2003 at 17:52 UTC
|
Are you saying that the END blocks don't run when you shut down the apache server? | [reply] |
|
|
They might; I haven't tried shutting down the server yet, because there's other unrelated code exposed there to the outside world, and I don't want to yank it out from under its users. Supposedly, the END blocks get run when the *child* exits (as opposed to the whole server), and that would be fine with me -- if it did that!
| -- |
| Jeff Boes |
| Database Engineer |
| Nexcerpt, Inc. |
|
|
|
...Nexcerpt...Connecting People With Expertise
|
| [reply] [d/l] |
|
|
It sounds like you don't understand when child processes exit in apache. They only exit when the server either shuts down or decides there are too many idle processes running and kills some. They can also exit when you hit MaxRequests for that process. There is no guarantee that any child process will ever exit before the final shutdown of the server though. If you want something to happen at the end of each request, you can either put that into your main handler code (or are you using Apache::Registry) or use a cleanup handler.
| [reply] |
|
|
|
|
|
|