The problem with this kind of thing in general is that the web is request/response based. Server-push (that is, having the progress subroutine print to the browser directly) is difficult to get right.
I've had some success with a similar problem by storing the process id of the forked process (or some other identifying value) in a session record (perhaps in a database table), and passing the key to that session record as a parameter to a progress script (e.g., "test_progress.cgi?session_key=whatever"). The progress script can then use the session key to look up the process id (or whatever), check whatever it needs to check, and regenerate the "in progress" page with a redirect to itself after some amount of time.
When the process is complete, the progress script can immediate redirect to a third script (or perhaps the original one, with a different parameter to identify the new context) for display of the output, which must have been stored somehow by the forked process, in a location identifiable by the same session key--I often use a generated filename in /tmp, with the hostname and process ID of the background process somehow incorporated in the filename, as the session key.
There can be irritating reliability (i.e., timeout) problems with your original idea of rewriting the page from the forked process. It may or may not work, depending upon how long the background process takes and other factors beyond your control, such as browser dependencies, server-side loading, etc., and whether or not the progress page itself contains </BODY> and </HTML> tags.
dmm
You can give a man a fish and feed him for a day ...
Or, you can teach him to fish and feed him for a lifetime
|