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

Hello All,

A very simple question today, but one who's answer could prove quite useful. Is there a way to capture when a script is killed because of a browser timeout? I have a script that could potentially run for a very long time and I'd like to politely tell people that a browser timeout has happened, inside the error log, as well as a few words of wisdom (of my own) on how to prevent the problem in the future.

I know there are all kinds of signals out there, but it's somewhat of a more low level function that this poor CGI scripter hasn't had much meditation on.

For extra points, the potential browser timeout function is inside a child process that's forked() off from the parent. I'm thinking that it would actually be easier to capture that signal.

Could anyone offer some insight?

Always appreciative,

-justin simoni
!skazat!

Replies are listed 'Best First'.
Re: Capturing a Browser Timeout Signal
by mr.nick (Chaplain) on May 25, 2001 at 01:02 UTC
    It's been my experience that when a browser times out, the script is NOT killed in anyway; it just continues to run.

    Try this and see what happen: create a script like

    #!/usr/bin/perl sleep 86400;
    and hit it from your web browser. Wait for the browser to timeout and see if the script is still running via "ps ax". I think you'll find that it is.
      even if the script still runs, the script sometimes gets killed by the webserver, usually script ran as 'nobody' or started by the webserver will time out to keep resources in the clear. perhaps this is really what I should be asking. how do I capture when the server kills the process

       

      -justin simoni
      !skazat!

        Try trapping the following signals:

        HUP, INT, QUIT, KILL, TERM, STOP, ABRT

        One of those will probably do it but I'm not sure which.

        To trap a signal, use the following:

        $SIG{KILL} = sub { print "This is my signal handling code. Log messages here.\n"; };

        BTW, you can get a list (in the form of a single string separated by single spaces) of all the signals your system supports like this:

        use Config; print "$Config{sig_name}\n";

        HTH

        bbfu
        Seasons don't fear The Reaper.
        Nor do the wind, the sun, and the rain.
        We can be like they are.

        Are you using Apache? My experience is that scripts will go on long after the connection is dropped.

        What type of run-time are you talking about? Minutes, Hours, Days?

        -Lee

        "To be civilized is to deny one's nature."
Re: Capturing a Browser Timeout Signal
by goughb (Initiate) on May 25, 2001 at 07:26 UTC
    If your using apache check this out: http://httpd.apache.org/docs/misc/custom_errordocs.html