Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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>).


In reply to Re: how to add progress bar to the CGI script by Sewi
in thread how to add progress bar to the CGI script by ashwin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-15 16:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found