in reply to Re: CGI progress indicator
in thread CGI progress indicator

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>