|
Posted by R Krause on 11/29/06 22:36
David T. Ashley wrote:
> I've noticed that some scripting languages (PHP, for example) have options
> to control whether the script can be terminated by the user clicking STOP on
> their browser (or similar mechanisms).
>
> How does this apply to CGI-BINs? Can Apache ever try to terminate a
> CGI-BIN, or does it just keep running and its output is discarded? Is there
> any signalling?
Excellent question. Unfortunately, Apache's behavior in exceptional
circumstances like this is not very well documented (and is one of my
biggest gripes :) Most of what I know is from experimentation and
perusing the Apache source code.
As was pointed out earlier, Apache responds to a SIGPIPE, by issuing a
SIGTERM to the CGI, then sleeping for three seconds, and then issuing a
non-interruptable SIGKILL. However, take note that Apache won't receive
the SIGPIPE unless you are writing to STDOUT (this is fairly standard
behavior with socket communication). This means that if the client
disappears while the CGI is performing a time-intensive operation,
there will be no notification of the disconnected socket until after
the CGI again writes to STDOUT. Additionally, if the CGI exceeds
Apache's configured timeout between successive writes to STDOUT, then a
SIGTERM will also be issued.
By not catching (or ignoring) the SIGTERM in either of these two
scenarios, your process will simply be terminated. About the only way
to be reasonably notified of a disconnected socket is to keep writing
to STDOUT. (It may even be possible to write nothing, which could force
a flush of the internal buffer, but I'm not entirely sure if that
actually works.)
--Randall
Navigation:
[Reply to this message]
|