Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: how to add progress bar to the CGI script

by Sewi (Friar)
on Aug 26, 2009 at 17:24 UTC ( #791397=note: print w/replies, xml ) Need Help??


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>).

Replies are listed 'Best First'.
Re^2: how to add progress bar to the CGI script
by ashwin (Initiate) on Aug 29, 2009 at 09:16 UTC
    Sewi,

    Thank you very much for the information

    I'll follow the things you mentioned and let you know how it goes.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://791397]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2021-11-27 11:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?