in reply to Stream or Broadcast Output from CGI script
1) Write a program which actually does the processing. This program should be completely independent of the CGI/web environment and able to be run from the command line, from cron, or from anywhere else. Output is written to either a database or a text file, depending on its complexity and what needs to be done with it.
2) Write a CGI interface which, when called, checks to see whether the program from #1 is already running and starts it up - still running as a separate, non-CGI process - if it isn't. Once the #1 program is running, grab its output and display it as a web page.
Putting the actual processing activity outside of the CGI environment is important if you want the person who originally starts the processing to be able to close their browser without aborting any remaining processing. It also has the side benefit that, if (when...) you someday want it to just run automatically whether anyone is watching or not, then you can set up a cron job to do just that instead of requiring someone to manually initiate it and then wait for it to complete.
|
|---|