perl cgi script buffering?

J

Jim Isaacson

Hi

I have a html doc that calls a perl cgi script to list or write a scsi tape.
If I submit from the html document on the local machine it displays the html
in the cgi script and then reads the tape. If I go to any other machine and
submit from the html doc it waits until it gets enough data and then
displays the html and tape listing ino. It's like its buffering data when
not run from the web server? It's driving me crazy and users think the link
is broken as it stays on the html page for so long. I've tried using $| = 1
and autoflush, it works fine on the local server, just not remotely from any
other machines browser.

Any help is appreciated, here it the cgi script and it runs on an Apache
2.0.55 server on Redhat linux.

Thanks
Jim

#!/usr/bin/perl

use FileHandle;

require "cgi-lib.pl";

&ReadParse(*in);

STDOUT->autoflush(1);

$file = $in{'file'};

$failed = 0;

$LOG = "/usr/local/apache2/htdocs/logs/tapelog.log";

print &PrintHeader;

print <<EOF;

<H1><CENTER>Writing file Tape</CENTER></H1>

EOF

print "<HTML><BODY>";

print "<h2>";

print "Writing $file tape now...Please Wait for Tape Complete Message<br>";

print "This can take up to 40 minutes...<br><br>";

print "</h2>";

print "<h3>";

print "<PRE>";

if(open(PIPE, "/usr/local/bin/rtape -t /dev/st0 $file 2>/tmp/tapewrite |"))
{

while(<PIPE>) {

print "$_";

}

}

if(-s "/tmp/tapewrite") {

$failed = 1;

$status = "Failed";

unlink("/tmp/tapewrite");

}

else {

$status = "Successful";

}

$date = `date '+%m/%d/%y %H:%M:%S'`;

chomp($date);

open(LOG, ">>$LOG") || die "Unable to open $LOG file\n";

print LOG "$date|$file|$status\n";

close(LOG);

print "</h3>";

print "<br>";

print "<br>";

print "<h2>";

if($failed) {

print "Write of $file tape Failed<br><br>";

}

else {

print "Write of $file tape complete<br><br>";

}

print "<A HREF=\"/index.html\">Return to Main Tape Page </A>";

print "</h2>";

print "</html></body>";
 
J

Jim Isaacson

Thanks for the info Jim. You were right. On the Linux box I was using
Firefox and on the pc clients it was IE. I loaded Firefox on a pc and the
cgi script loads up right away.

Now I need to see if there is an option or way to kickstart IE.

Thx

Jim

Jim Gibson said:
Jim said:
Hi

I have a html doc that calls a perl cgi script to list or write a scsi
tape.
If I submit from the html document on the local machine it displays the
html
in the cgi script and then reads the tape. If I go to any other machine
and
submit from the html doc it waits until it gets enough data and then
displays the html and tape listing ino. It's like its buffering data when
not run from the web server? It's driving me crazy and users think the
link
is broken as it stays on the html page for so long. I've tried using $| =
1
and autoflush, it works fine on the local server, just not remotely from
any
other machines browser.

The way in which an HTML page is displayed is under the control of the
server and your browser, not the CGI program that generates the page.
There is little your CGI program can do to influence when the page is
displayed.

See, for example, the article "Watching long processes through CGI",
Randal Schwartz, Linux Magazine, Aug 2002:
Any help is appreciated, here it the cgi script and it runs on an Apache
2.0.55 server on Redhat linux.

Your program looks like it was written 10 years ago. You should
consider re-writing it using more modern Perl programming techniques.
For example, the CGI.pm module has replaced the cgi-lib.pl library, and
it offers easier-to-use, more flexible and secure features. Adding 'use
strict' and 'use warnings' to your script will help catch programming
errors. Perl now has lexical variables, and you don't have to call
subroutines with & in front of the subroutine name. Perl has "here"
documents for generating a lot of output. (and there's more).

Good luck.

[perl script snipped]
 
B

Brian Wakem

Jim said:
Thanks for the info Jim. You were right. On the Linux box I was using
Firefox and on the pc clients it was IE. I loaded Firefox on a pc and the
cgi script loads up right away.

Now I need to see if there is an option or way to kickstart IE.


I have done this in the past by printing lots of hidden data.

print "<!-- nobody will get to see this text, unless they view the source,
but there wont be anything interesting here anyway -->" x 150;
 
X

xhoster

Brian Wakem said:
I have done this in the past by printing lots of hidden data.

print "<!-- nobody will get to see this text, unless they view the
source, but there wont be anything interesting here anyway -->" x 150;

I almost never find that necessary. The OP would be better off just
generating valid html in the first place. If I move the printing of the
<H1><CENTER> stuff from before to after the opening <HTML> tag, then IE
starts behaving the way he wants.

Xho
 
M

Matt Garrish

I almost never find that necessary. The OP would be better off just
generating valid html in the first place. If I move the printing of the
<H1><CENTER> stuff from before to after the opening <HTML> tag, then IE
starts behaving the way he wants.

You mean print valid html? IE couldn't possibly handle that, could it? : P

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,031
Latest member
AndreBucki

Latest Threads

Top