http://www.perlmonks.org?node_id=478109

esskar has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
this is a following up question of the own "mod_perl" implemenation-node. I already posted this question there (Re^2: own "mod_perl" implemenation) but i think i got lost.

As you can see, i want to do a little speed up for my web scripts.
I wrote two applications a NamedPipe Server and a NamedPipe Client. The WebServer just calls the NamedPipe client as it would call the perl binary to run a cgi-script. The Client than connects to the NamedPipe Server which holds a number of precompliled instances of the script. I feed one instance with the data just received from the client and redirect the output back to client. It's quite fast. I'm running a catalyst application which is really fast no compared to CGI mode.


But if the script's calls exit, or die, the whole pipe-server shuts down. I know how to override perl internals (see the other node) but i want to achive that calling exit, die, ... really ends the script but not pipe-server.
So how do i have to implement myexit? Any ideas?

Replies are listed 'Best First'.
Re: Overwriting exit and similar
by Fletch (Bishop) on Jul 26, 2005 at 10:58 UTC

    Not to answer your problem, but it sounds like you've re-implemented a wheel, namely FastCGI.

    Update: And to answer your question, Apache provides its own Apache::exit sub. Things like Apache::Registry do a use Apache qw( exit ) so that its version is called rather than CORE::exit. (For mod_perl 1)

    --
    We're looking for people in ATL

      I know FastCGI, SpeedyCGI, ... but it's not what I'm looking for. I think they fork their processes anyway... but that is not what i want to do!
Re: Overwriting exit and similar
by jhourcle (Prior) on Jul 26, 2005 at 11:55 UTC

    The easiest way to trap die is to just put everything in an eval block. Also see die for info about what you can do with $SIG{'__DIE__'}.

    exit is a little trickier, but you might be able to set something up in an END block. (I've never tried, myself... I'm not sure what would happen if you did a goto in an END block). I'd think you'd be better off just removing calls to exit, or changing them to die where appropriate, if that's possible.