in reply to CGI progress indicator

Instead of making the user wait for the emails to finish, why not start a detached process to do the mailing and let the user go and look at the progress on a separate page ... or not, as, if and when he wants to review that progress. The detached program could record its progress in a file loaded up by the page where he can review that progress.

Update: Of course, even users expect that even when mail is sent it takes time to be received anyway. The delay between sending and receiving is all the user sees, so why bother to take your part of it out of the closet? It was only the making the user wait instead of detaching that made it seem (temporarily) attractive to do so.

One world, one people

Replies are listed 'Best First'.
Re^2: CGI progress indicator
by techcode (Hermit) on Aug 25, 2005 at 19:25 UTC
    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>