in reply to Don't understand END blocks in mod_perl

Are you saying that the END blocks don't run when you shut down the apache server?
  • Comment on Re: Don't understand END blocks in mod_perl

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