Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Forked Process using CGI

Posted on 1998-03-05
8
Medium Priority
?
195 Views
Last Modified: 2013-12-25
I have a CGI program that is very time consuming and I would like to fork a process to do all the calculations while the original process will print a status message to the screen.  Once the calucations are finished, then the results will be displayed overwriting all the status messages.  The reason I need this is because when a user hits "Submit" they have ti wait a long time and therefore think nothing is happening, so they hit "Submit" again and of course it starts all over.  Can this be done?

Thanks,
Shawn
0
Comment
Question by:sgrobins
  • 4
  • 3
8 Comments
 
LVL 5

Expert Comment

by:icd
ID: 1832070
Not sure if what you want can be done cleanly.

I have seen some pages that output a 'status' message as the calculation is being done, this would probably work but I think you need to cause the stdout to be 'flushed' after each status report. You would also need to be careful of outputting the status report in a table, this could cause your browser not to output any text until the end of table was reached and defeat the whole exercise.

A second alternative is to output data to a chron job or daemon that creates a page containing the data. The page the user would see would have a link to this page and a message that tells the user what time the page would be available. (I am thinking here of a process that could take several minutes, a problem I once had on a contract). The pages could be purged after, say, 24 hours.

0
 
LVL 5

Accepted Solution

by:
julio011597 earned 800 total points
ID: 1832071
The easiest way is just unbuffering your CGI's output and begin to write the document, so that the user will see a page coming as soon as you write something out.

To overwrite the document, you could use JavaScript on the client side, and the methods provided by the "document" object (e.g., write() and related).

Feel free to ask more.
0
 

Author Comment

by:sgrobins
ID: 1832072
I have already thought of that idea, the problem is my entire results page that is created is in a table and therefore does not get shown.  I cannot change that.  I also thought of the idea of having a temporary file that has the status message in it and that auto-reloads itself say every 2 seconds, then my original data will override this file with the results (without the auto-reload mechanism).  Kinda clumsy though, cause then the URL will be changed and a temporary file would have to be created/deleted.  Hmmm.. I thought there might be a better way.
0
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
LVL 5

Expert Comment

by:julio011597
ID: 1832073
Just to go further, search engine designers have to face a similar problem; sometimes queries require a long time (exact phrases in particular)  and they don't want people go away or hit the reload button; also, they often show results formatted in tables...

The usual way requires these two steps:

1. as soon as possible make their CGI output all header information (unbuffered); i.e. the Content Type stuff and the first part of the result page - say, banners and logos, links to other pages, current search criteria, and so on; think, also, that download of images happens asynchroneously, so that the server processes make use of some of the time the user would waste anyway;

2. make each row of the result table be a table by itself, so that users see results coming as soon as they are sent back; having different tables keep equal column widths may be achieved with use of transparent images being 1 pixel of height and some needed number of pixels of width.

Would this approach fit for your needs?
0
 

Author Comment

by:sgrobins
ID: 1832074
That might work as a temporary solution.  Again, the problem is the very first part of the code is <table border=0 width=600>, so nothing will show up except the background image.  Basically, I mirrored www.cnet.com 's style of having the menu information on the left.  I have thought of another solution: will this work?

I have the cgi script check to see if a PID was passed in as an argument.  If not, then create a file and put a 0 in it. Then fork a child process and have the child process call the same cgi script but with the same PID as an argument.  The cgi script now sees the file with a 0 in it, so it just prints a "Processing...." and reloads every 5 seconds.  The parent process (of the original script) does all the processing and once it is finished, prints a 1 in the file with all the results information.  So, that when the child process (or actually the reloaded cgi script) sees a 1 in the file, it just prints all the results (without the reload feature).

What do you think?

0
 
LVL 5

Expert Comment

by:julio011597
ID: 1832075
Sure, i would expect it to work - BTW, i guess you are going to build your temporary files' names upon the referring PID, in order to avoid conflicts.

As a web developer, in general i'd better prefer to change my result page design, because your solution doesn't sound very elegant... but, of course, you know much more than me on the problem to be solved.
0
 

Author Comment

by:sgrobins
ID: 1832076
I agree, I don't like the solution either.  Definitely not elegant.  I will see what we can do about the results page and hopefully go the better / easier route.  Thanks for all the help!
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1832077
Glad to have been of any help.

Good luck.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question