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

This may be more of an Apache than Perl question, but can anyone tell me what happens if a CGI script is executing and the user hits 'stop' or just closes their browser? Does the script still run until 'exit;' or does it get a SIGTERM or SIGKILL or something sent to it?

Also, is there anything that might cause a DBI connection handle to *NOT* get destroyed, leaving connections to a DB hanging open after the process is gone?

Replies are listed 'Best First'.
Re: CGI behavior/handling
by btrott (Parson) on Jul 19, 2000 at 23:03 UTC
    For your first question: Handling the User Pressed Stop Button Case.

    In response to your second question: are you running under mod_perl? Is your database handle global? If so, the handle will remain open, which will make the database connection remain open. Or you could be using Apache::DBI, which would also force your connections to stay open.

Re: CGI behavior/handling
by Anonymous Monk on Jul 20, 2000 at 00:25 UTC
    No, I am not running mod_perl, this is just a normal CGI script. Which leads me to believe that all database connections should die becuase the destroy method gets called on the database handle when the script exits, regardless of whether you explicitly call $dbh->disconnect(), right?
      Depending on your database server the statment handles may still be open (or at least using resources in the RDBMS) even after you close your database handle. Make sure you have an $sth->finish() for each of your statment handles (if you want to be really paranoid, undef them after you finish them). Try running your script (or a slimmed-down version of it) from the command line and using the trace command ($dbh->trace(1)) and examine the output.
        Thanks. I'm still not certain which of 2 scripts caused the problem, but I did forget to call $sth->finish() in one of them. I enabled $dbh->trace(1) (and then 2 :) and couldn't find anything wrong. Hopefully it works now.

        This brings another question to mind: under the right (or wrong...) conditions, I might have a SQL query that hangs for a long time. Supposedly, the webserver has a cron job that kills CGI processes after 15 minutes of execution. Is it possible that whatever signal this cron job sends could cause Perl to exit without calling the destroy method on the database handle?