Avoiding Browser timeouts
words of wisdom from klooloola
There must be a better way to avoid browser timeouts while your CGI is waiting for scripts to finish but here is what i found. it just sets the alarm signal which when called outputs a html comment to keep the browser happy.
select(STDOUT);
$| = 1; # make unbuffered
alarm(2);
$SIG{“ALRM”} = sub {print “\n”;alarm (2);};
# do a lot of waiting for other scripts to finish here ex
$results =`slowprogram`;
# when done
$SIG{“ALRM”}=”IGNORE”;
print $results;
What I usually do in PHP is output some kind of progress bar using flush() BUT this works only if you are in a long long loop eg inserting 200K records, but if a single operation is taking so long (why?) that the browser times out then this will not work .
BTW doesn’t a CGI (Perl?) script itself time out when it exceeds the default maximum execution time?
I basically need to get info from 20 diff machines ( on-the-fly) , process the output and display them.
I use LWP, and this could take couple of minutes at times.
Just keep throwing something at the browser output and it will not time out