Link to home
Start Free TrialLog in
Avatar of tplai
tplai

asked on

Communication problem between CGI and browser

Client : Nestcape Navigator or Nescape Communicator or MSIE 3
Server : Netscape Enterprise Server

When I submit a form, calling my CGI, my client doesn't understand the ending of this CGI. So, the client is still looping, even when the end of the CGI is reached. The CGI accesses a database, and then sends an HTML page to the client, with a Location. Sometimes, when the processing of the CGI is fast, there is no problem and the HTML page is correctly displayed.

On the server side, in all cases, the response is correct (for instance : ... "GET myCGI ... HTTP/1.0" 200 847, where 847 is the size (in bytes) of the HTML page.

Thierry PLAI - FRANCE
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Do you flush the server cache in the cgi?
Do you have a linefeed after the last line of html
Is that last line </HTML>

If the cgi only gives a location do you have the extra linefeed after the last http-header?

Michel
Avatar of tplai
tplai

ASKER

>Do you flush the server cache in the cgi ?
How can I do this ?

>Do you have a linefeed after the last line of html ?
Yes.

>Is that last line </HTML> ?
Yes.

>If the cgi only gives a location do you have the extra linefeed after the last http-header ?
Yes. Sometimes, that works !
In perl:

 $| = 1;

From the perl faq:

autoflush HANDLE EXPR
$OUTPUT_AUTOFLUSH
$|
     If set to nonzero, forces a flush after every write or print on the currently selected output channel. Default is 0 (regardless
     of whether the channel is actually buffered by the system or not; $| tells you only whether you've asked Perl explicitly to
     flush after each write). Note that STDOUT will typically be line buffered if output is to the terminal and block buffered
     otherwise. Setting this variable is useful primarily when you are outputting to a pipe, such as when you are running a Perl
     script under rsh and want to see the output as it's happening. This has no effect on input buffering. (Mnemonic: when you
     want your pipes to be piping hot.)

Michel
Avatar of tplai

ASKER

My CGI is written in C. In that case, you suggest to call fflush(stdout) at the end of my CGI ?
Yes!

Michel
and even in the middle too if it takes long to format the data (only works from the time you start outputting HTML)

Michel
Avatar of tplai

ASKER

Without fflush, the server processes correctly my CGI. In the log server file, the size of the HTML page I want to disply is correct (... "GET myCGI ... HTTP/1.0" 200 847, where 847 is the size (in bytes) of the HTML page).
The web server logging the access should tell the connection has succesfully completed (well, unless i'm wrong), so the problem should be on the client side - that is, i'd also investigate the HTML output.

Can you show the HTML output you are sending, or better yet is your cgi online to test it?
Also, the client hangs at the end of the page? In the middle? What source can you see after hitting stop?

-julio
Avatar of tplai

ASKER

The HTML output is correct and I can show it. I have transferred my CGI on an other computer with more memory and it seems working correctly. I think this problem is due to less resources on the first computer.
So you answered your own question: Sometimes, when the processing of the CGI is fast, there is no problem and the HTML page is correctly displayed.

Glad to hear it works

Michel

PS: Flushing stdout for 847 bytes is a bit overkill anyway ;-) I work more in 100KB+


ASKER CERTIFIED SOLUTION
Avatar of jconde
jconde

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I just install a MIIS 3 server in my NT machine. When I click on the button to execute a cgi script from the Web page, the browser opens the script as a text file or open the save as window. I tried everything :
-Permission (full access granted)
-Run the program in the command line. (it runs w/o problems) .
-Run the same program in a UNIX web server (it runs w/o problems).
Can you help please.

Wal
tplai, I had a similiar problem on executing my CGI's in C and mplungjan solved my problem in that my CGI's were not terminating correctly. The problem was that I was not compiling in a 32 bit compiler I was using 16 bit. This is just a footnote for you because I lost alot of hair and sleep till mplugjan helped me resolve it....
Randall

waleed,
 Two things: First I would assume you meant to post this as your own question not as a comment for tplai, and second a possible solution as to why your CGI is not working correctly would be to check case sensitivity of your executable name. I have been caught a couple of times when a file is edited of it changing the capitalization of the file name. If that happens depending on your how your CGI is returning the page can cause it to open in a window. Check that out and let me know . Hope this helps...

Randall