in reply to Re: Re: Don't understand END blocks in mod_perl
in thread Don't understand END blocks in mod_perl

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.
  • Comment on Re: Re: Re: Don't understand END blocks in mod_perl

Replies are listed 'Best First'.
Re: Re: Re: Re: Don't understand END blocks in mod_perl
by Mur (Pilgrim) on Sep 26, 2003 at 14:20 UTC
    Um, no, I understand that. I have a database connection in that child process, and it's represented by a row in a table. When the connection is closed, I want the row to be deleted first.

    The connection will close when the handle goes out of scope, but for global handles that doesn't happen at the right time. So I'd like to have an END block kicked off when the child exits (not when the request completes, that's too soon; not when the server exits, that's too late).

    What I may be missing is just what happens to a child when you do a "killall -HUP httpd"; I believe the child exits and a new one takes its place. However, the END blocks are not run, apparently.
    --
    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

      Okay, so the actual problem here is that your END blocks don't seem to run when you HUP the server? Have you tried putting in warnings in the END blocks to be certain that they aren't running?

      Keep in mind that when you load the package with the END block makes a difference. If you load it during startup, it is supposed to run when each child exits. If you load it from an Apache::Registry script (or if it is in that script), it is supposed to run after each request.

      By the way, usually the support for this kind of question is better on the mod_perl list than on PerlMonks, since there are more people there who are familiar with the internals of the mod_perl code.

      Would it be possible to use only lexically scoped ('my') handles or do an explicit disconnect() at the end of your script?

      What I don't understand is why you would need to have database connections alive after the script ends. Are your trying to pool database connections and in that way save on the cost of connecting each time? Doesn't Apache::DBI do that already?

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law