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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/MySQL/CGI -> hangs?

Status
Not open for further replies.

Coderifous

Programmer
Dec 13, 2001
782
US
Hey all,

I'm developing Perl-Powered websites w/ backend DB's in MySQL. I use DBI.pm. For admin use, I have a script that dumps the contents of a MySQL table, into an HTML table to the browser. This works 99% of the time without a hitch. I mean - it takes a minute, but thousands of lines will dump to the browser if that's what I tell it to do. No problem there.
Here's the problem:
I wrote a script to do this routine 'dump' on another routine table. As you can see, there is nothing special so far. However, when I execute the script via browser - it hangs. It 'prints' everything up to the beginning of the table and then stops. (So I can see the page title, header, and that's it). After waiting any arbitrary amount of time (it can be 2 seconds or 10 minutes - doesn't matter) I'll click the 'stop' button on my browser, and that's when (using MS Internet Explorer) the available tables contents are displayed. It's not the whole table though. The HTML stops at the same point everytime. Like for some reason MySQL just stops talking right there, and the rest of the processes are just sitting there waiting - wondering.
I don't know if I was very clear on this, but the bottom line is, MySQL is causing my script to hang and it shouldn't. Has anyone else heard of/dealt with this behavior? Would enjoy a little assistance. And oh yea, here is some of my code (I'll abrreviate some peices):


Code:
...

my $query = "SELECT * FROM access_log ORDER BY date";
my $dbh = WebDB::connect('access');  #personal module
my $sth = $dbh->prepare($query);
$sth->execute();

print <<EOF;
<!-- Some HTML here that starts the table -->
EOF

while(my @results = $sth->fetchrow_array()){
   local $\ = &quot;\n&quot;;
   print &quot;<TR>&quot;;
   shift @results;  # toss the id field,
                    # don't need it here
   print &quot;<TD>$_</TD>&quot; for @results;
   print &quot;</TR>&quot;;
}

print &quot;</TABLE>&quot;;

...

Keep in mind that, syntactically, everything is fine. I don't think it's Apache since other similar scripts run just fine (and return larger and smaller datasets). I really think it's MySQL.

Thanks - I hope.

--jim
 
If you're using IE, it might be that Apache is keeping the connection alive. Under some conditions, some versions of IE won't render tables until the connection closes. Hitting stop forces the connection to close, allowing the rendering engine to do its job.

There is a server configuration parameter for Apache that will tell Apache to use no keepalives for IE.
 
Don't know how, but I fixed it:
OLD Loop:
Code:
...
while(my @results = $sth->fetchrow_array()){

   #this was the problem!!!!?!?!?!
   my $color=($color eq $WebDB::color_1)?
      $WebDB::color_2 : $WebDB::color_1;
   

   local $\ = &quot;\n&quot;;
   print &quot;<TR>&quot;;
   shift @results;  # toss the id field,
                    # don't need it here
   print &quot;<TD>$_</TD>&quot; for @results;
   print &quot;</TR>&quot;;
}

print &quot;</TABLE>&quot;;

...

New Loop:
Code:
...

while(my @results = $sth->fetchrow_array()){
   
   #take away the my() declaration and I'm good to go.
   $color=($color eq $WebDB::color_1)?
   $WebDB::color_2 : $WebDB::color_1;
   

   local $\ = &quot;\n&quot;;
   print &quot;<TR>&quot;;
   shift @results;  # toss the id field,
                    # don't need it here
   print &quot;<TD>$_</TD>&quot; for @results;
   print &quot;</TR>&quot;;
}

print &quot;</TABLE>&quot;;

...

Can someone else try this out and see if it hangs for them too? I sure would like to know if we've found a perl bug.

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top