http://qs321.pair.com?node_id=791397


in reply to how to add progress bar to the CGI script

At first: Use$|=1as early as possible in your script (usually you have #!/usr/bin/perl, use someting; $|=1;) otherwise your progress won't be shown until your script is done.

Here is what I'm using:

#!/usr/bin/perl $|=1; print '<header>'; # placeholder for your whole HTML header block print '<span id=Progress>Working...</span>'; print '<footer>'; # placeholder for the rest of your document until bu +t without </body> sleep 1; # Something is done here print <<_EOT_; <script language=JavaScript type=text/javascript><!-- document.getElementById('Progress').innerHTML='Still working...'; //--></script> _EOT_ sleep 1; # Something is done here print <<_EOT_; <script language=JavaScript type=text/javascript><!-- document.getElementById('Progress').innerHTML='Sorry, still not finish +ed...'; //--></script> _EOT_ sleep 1; # Something is done here print <<_EOT_; <script language=JavaScript type=text/javascript><!-- document.getElementById('Progress').style.display='none'; //--></script> _EOT_ print '</body></html>'; # Page finished
I learned that most people prefer this:
#!/usr/bin/perl $|=1; print '<header>'; # placeholder for your whole HTML header block print '<img src=animated.gif id=Progress>'; print '<footer>'; # placeholder for the rest of your document until bu +t without </body> sleep 1; # Something is done here sleep 1; # Something is done here sleep 1; # Something is done here print <<_EOT_; <script language=JavaScript type=text/javascript><!-- document.getElementById('Progress').style.display='none'; //--></script> _EOT_ print '</body></html>'; # Page finished
Once I had a customer waiting three hours for the result not knowing that his internet connection broke early after starting the job.

These solutions are not the best ones - they don't use any modules. But they're simple and work for me in a number of projects. You could also output your data & footer after finishing the processing. In this case, add a <br>\r\n behind the Progress-object to force flushing the buffer (\r\n), sending to the client and showing to the user (<br>).