hambo has asked for the wisdom of the Perl Monks concerning the following question:

Hello folks. I have another CGI related problem. I have a script that forks a number of jobs that need doing. I the main part of the script, I want to check whether the children are done. Each child sets a temp file, and the main script checks whether the temp files are still there. If so, then it generates an html page. If not, then it should generate a popup html page asking the user for more input. Once the user has given their input, the main script should continue with it's new set of tasks.
Here is my pseudo-code
create list of things that need doing do fork jobs while jobs still running { generate information HTML page sleep 30 seconds } last if list of things to do empty pop_up HTML page in new window for users to provide more input wait for users input until ( we've exhausted the list of things that need doing ) generate 'Thanks. We're all done now' HTML page
I have thought of doing the "wait for users input" bit using cookies. I would get the original loop to check whether the cookie is set. If so, then the user has pushed "OK", then we delete the cookie and continue in the loop.
My problem is that I am not sure how to really code this from a CGI perspective

Thanks people
H

Update: Steve_p - Changed title from YA CGI question

Replies are listed 'Best First'.
•Re: Using fork() with a CGI program
by merlyn (Sage) on May 06, 2004 at 10:13 UTC
      Thanks Merlyn,
      It will take me some time to understand this.
      I ran said program and it produced output, but not in quite the way I was expecting. I expected it to print out 1/2 lines at a time as the traceroute returned information.
      Instead, the hour glass just hung around till all the output was received.
      I am not really concenrned with the output of the jobs I need to do. I am more interested in being able to pop-up a new window asking them to change some physical media when the first set of jobs is done
      Then I want to begin the process over again
      Thanks again for the help
      H
Re: Using fork() with a CGI program
by BUU (Prior) on May 06, 2004 at 09:28 UTC
    Unless you want to embark on the strange and perilous road of trying to implement server-push, you are stuck with the default http environment, which is, client pull. What that means is you can only send stuff to the client when it asks for it. Theres no way, short of server-push, to magically send data to a client unless it requests said data.

    In this case the best bet is to probably try to emulate server push by having three 'scripts' (or modes or whatever).

    Mode 1 simply starts the process then sends the user to mode 2.

    Mode 2 checks if the child process is done. If it's done, it redirects the client to mode 3, other wise it simply says "wait 3 seconds and ask me again". You can acheive this "wait x seconds and ask me again" a number of ways, most of them involving the refresh header. For example: <META HTTP-EQUIV="Refresh" CONTENT="10; URL=url"> in the html. Or javascript or an actual http refresh header.

    Mode 3 displays the results of the child jobs.