Solved

Forked Process using CGI

Posted on 1998-03-05
8
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

734 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