Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Forked Process using CGI

Posted on 1998-03-05
8
Medium Priority
?
196 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

580 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