Solved

Forked Process using CGI

Posted on 1998-03-05
8
183 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 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now