I'd like to add a bit to this idea. I used it once in a project, and it worked just fine. But I cant remember the exact method that I used.

EDIT: I might have mistaken ... The problem with starting a new process is that you can do that while working under CGI. Maybe I'm wrong? You cant use fork/system or similar as they block the execution of your script - and threads are usually not "compiled in" for CGI usage. And even if they were, what happens to child's if parent ends itself.

The idea is that you actually (re)generate page every few seconds - in your case, you may put it inside of loop that is sending the emails and make it print something like : "Sent X emails out of Y". Or calculate how much email have you sent in %. Something like : $percentage = (100 * $sent) / $total_emails ... and then generate a table (html table) where you set bgcolor and it's width=$percentage. I hope it's clear - if not, I can try to explain a little better.

You then save that output as HTML file, say progress.html and refresh it every 2, 3, 5 ... seconds by using meta refresh in it's head.

The only question is how to get the browser to load that page. Plain redirect (by header) wont do it, as browser will wait for your script to finish loading. If I recall right (I lost original project code) I did it with JavaScript. Just output something like following by your script and it should redirect the browser (if it has java enabled) as soon as it receives that part of the page.

<html><head><title>Blabla</title></head> <body> <script language="JavaScript"> location = "http://your-site.com/progress/html"; </script>


In reply to Re^2: CGI progress indicator by techcode
in thread CGI progress indicator by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.