in reply to Don't understand END blocks in mod_perl

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

Replies are listed 'Best First'.
Re: Re: Don't understand END blocks in mod_perl
by Mur (Pilgrim) on Sep 26, 2003 at 14:24 UTC
    (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.
    vox 269.226.9550 ext 24
    fax 269.349.9076
     http://www.nexcerpt.com
    ...Nexcerpt...Connecting People With Expertise

      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