Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to display a graphical progress bar using a browser when sending many newsletter emails to our clients (500 or so). I am still testing, but when the submit button is hit, the page will just stay and only display the recieving page once all emails have been sent.

Replies are listed 'Best First'.
Re: Mail Progress Bar
by atcroft (Abbot) on Jun 19, 2005 at 12:13 UTC
Re: Mail Progress Bar
by ruoso (Curate) on Jun 19, 2005 at 13:01 UTC
    I'd suggest you the use of NPH, which is the support for continuosly sending information to the client without closing the conection. This is how most webchat clients work. Here is a good explanation of a non-parsed headers cgi.
Re: Mail Progress Bar
by rob_au (Abbot) on Jun 19, 2005 at 22:33 UTC
    Another option, building upon the column by merlyn linked to by atcroft, would be to employ the Javascript XMLHttpRequest object to communicate with the server and update an element of your web page with the progress (as reported by the server) of a detached, long-running process. The advantage which this method would have (to my mind) is that you could browse away from the page and return at a later stage to check on progress (or have the process checked upon by non-initiators of the long-running process).


    perl -le "print unpack'N', pack'B32', '00000000000000000000001000000000'"

      I was playing around with that stuff a couple of weeks ago to try and build an upload meter (something like Apache::UploadMeter but using XMLHttpRequest). I have a rough prototype of it working that you can check out here:

      It was written to work with Firefox so you may not see anything if you are using another browser.

      The code is downloadable from that page, but remember that it is just a proof of concept (that means no documentation, just code). I am not using this stuff in production anywhere, but hope to wrap it up into a clean package at some point.

      Anyway, back to the question, it would be pretty easy to do a similar thing with a standard progress bar instead of as an upload meter.

Re: Mail Progress Bar
by fauria (Deacon) on Jun 19, 2005 at 16:23 UTC
    I dont know, but maybe you only want to show that there is being activity while sending newsletters. If thats the case, you can simply use an animated gif of a progress bar inside a while() loop, and then redirect to wherever should be when finished.
Re: Mail Progress Bar
by TedPride (Priest) on Jun 19, 2005 at 22:20 UTC
    What I do is set the script to flush the buffer after every print ($| = 1) and print a message after every email is sent, then view the output in a browser that doesn't buffer it (I use an early version of NS, but I imagine there are other options). Since this is for your own use, the output doesn't have to be pretty.

    You could also use a frames layout with one frame running the script and another loading and refreshing an output file, which would be updated every email or x number of emails with the current status.