Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI process sleeps if client double-clicks link

Status
Not open for further replies.

AngryBoy

Programmer
Feb 22, 2005
1
FI
Hi,

Sorry if this has been covered before, but I couldn't find anything on the web even though I'm sure it's fairly common.

We've had an intermittent problem of processes not being killed on our server for one of our cgi scripts. I finally discovered today when this happens: it's if someone either double-clicks the link (most common), or closes their browser window before the cgi has completed.

I think this is because the script prints directly to STDOUT, ie the client browser window, and if this is no longer available to print to, then the process just sits and waits forever rather than dying.

I did not write this script! And I must admit I don't often write perl scripts. I would have written it differently but I don't have the time right now. Is there a way of forcing the process to die if STDOUT disappears? The cgi is called directly via a link, not through a form.

I'll show you the code if it will help, but it's pretty simple, here's a snippet:

Code:
} elsif($cd1) {
    print $query->header;
    &textpageheader("Dali database: select structural neighbours of $cd1");
    &fetch_cd2list_sql($cd1);
    &textpagefooter;
}

In this case, the "fetch_cd2list_sql" subroutine takes a couple of seconds as it has to query our database and return a long list.

Any help much appreciated!
Chris
 
I can not see enough code to understand what is happening but it seems as though you enacted a process that does not end under certain conditions.

Double clicking a link or closing the page will not continue a process as perl has built in functions to eliminate this.

You probably have a while loop that when a condition is met the script enters the loop, never to exit. Like if you said:

Code:
$var = 1;
while($var)
 {
 print "a";
 }

The page will continu to print "a" forever, untill the page is closed, or changes.

This is not a problem, but when you are executing a query to a database, the database does not know when it is done, and the CGI sees itself as always doing something, so it never ends...

I once inserted 1.4+ million records into a database with an unended cycle..ooops!

If you can find where the scrip is looping try placing the word:

die

without a ";" or anything...

Here is the format your databse should connect:

Code:
use DBI;
$string = "select * from `table` where `color`='red'";

$dbh = DBI->connect("DBI:mysql:db_name:localhost","db_username","db_pass")
or die print "Couldn't connect to database: " . DBI->errstr;

$sth = $dbh->prepare($string)
or die print "Couldn't prepare statement: " . $dbh->errstr;

$sth->execute()
or die print "Couldn't execute statement: " . $sth->errstr;


You should probably post more code to pinpoint the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top