print buffer in Perl 5.10

J

John

Hi

Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.

Normally I use:
our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
socket hot
but this appears no longer to work and output is now buffered.

Any ideas?
John
 
J

John

Ben Morrow said:
That construction (ugly as it may be) ought to still work in 5.10.
Please post a complete, short script that we can run which demonstrates
your problem.

Ben

The proram is embarrassingly small but I cannot stop the print buffer.

#!/usr/bin/perl
use strict;
use warnings;

# use FileHandle; STDOUT->autoflush(1);
our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
socket hot

print "Content-type: text/html\n\n";

print "hallo\n";
print "hallo<br>\n";
sleep(5);
print "hallo<br>\n";
sleep(5);
print "hallo<br>";
sleep(10);
print "hallo<br>";
sleep(2);

Regards
John
 
J

Jim Gibson

John <[email protected]> said:
The proram is embarrassingly small but I cannot stop the print buffer.

What do you mean by "stop the print buffer"?
#!/usr/bin/perl
use strict;
use warnings;

# use FileHandle; STDOUT->autoflush(1);
our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
socket hot

print "Content-type: text/html\n\n";

print "hallo\n";
print "hallo<br>\n";
sleep(5);
print "hallo<br>\n";
sleep(5);
print "hallo<br>";
sleep(10);
print "hallo<br>";
sleep(2);

The program can be made even smaller and still demonstrate the
condition (I hesitate to call it a "problem" as I do not know what the
problem is.)

#!/usr/local/bin/perl
use strict;
use warnings;
our $old_fh=select(STDOUT); $|=1; select($old_fh); #line 4
for my $n ( 1..5 ) {
print "Line $n "; # line 6
sleep(2);
}
print "\n";

Note that if you replace line 6 with:
print "Line $n\n";
on my system (Mac OS 10.5.7, Perl 5.10.0), the newline character forces
a flush regardless of the autoflush setting on STDOUT. You need to run
the program as shown above with and without line 4 to see the
difference.

Your program looks like a CGI program. Are you trying to run it from a
command-line or from a browser? That will certainly affect your
expected results.

Please explain in more detail the problem you are trying to solve.

Thanks.
 
J

John

Jim Gibson said:
What do you mean by "stop the print buffer"?


The program can be made even smaller and still demonstrate the
condition (I hesitate to call it a "problem" as I do not know what the
problem is.)

#!/usr/local/bin/perl
use strict;
use warnings;
our $old_fh=select(STDOUT); $|=1; select($old_fh); #line 4
for my $n ( 1..5 ) {
print "Line $n "; # line 6
sleep(2);
}
print "\n";

Note that if you replace line 6 with:
print "Line $n\n";
on my system (Mac OS 10.5.7, Perl 5.10.0), the newline character forces
a flush regardless of the autoflush setting on STDOUT. You need to run
the program as shown above with and without line 4 to see the
difference.

Your program looks like a CGI program. Are you trying to run it from a
command-line or from a browser? That will certainly affect your
expected results.

Please explain in more detail the problem you are trying to solve.

Thanks.

Yes it is run from a browser.

Since autoflush has been set then each line should be printed immediately
followed by a wait of so many seconds.

At present, all the output is buffered and then printed at one go.

At the weekend we upgraded the server from Debian Etch to Debian Lenny, and
from Perl 5.8.8 to Perl 5.10.

Previously the autoflush was working.

Regards
John
 
J

Jim Gibson

Yes it is run from a browser.

Since autoflush has been set then each line should be printed immediately
followed by a wait of so many seconds.

At present, all the output is buffered and then printed at one go.

At the weekend we upgraded the server from Debian Etch to Debian Lenny, and
from Perl 5.8.8 to Perl 5.10.

Previously the autoflush was working.

You can run the program included above from a command line to test
whether your Perl installation performs autoflushing correctly.
Hopefully, it does.

It is more likely that your web server or browser has changed behavior.
Autoflushing Perl's STDOUT means that partial lines will get to the web
server promptly. It doesn't mean that the web server will send the
lines to the browser promptly, or that the browser will display those
lines promptly in a browser window. Unfortunately, I don't think Perl
is going to be able to help you with this problem without a major
re-implementation. See, for example, the article:

<http://www.stonehenge.com/merlyn/LinuxMag/col39.html>
 
P

Peter J. Holzer

[...]
The proram is embarrassingly small but I cannot stop the print buffer.

[program snipped]

Your program works fine on Debian Lenny. To test, invoke it like this:

$ ./john | cat

It will wait after each "<br>".

hp
 
J

John

Peter J. Holzer said:
Ben Morrow said:
Quoth "John" <[email protected]>:

Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.

Normally I use:
our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard
output
socket hot
but this appears no longer to work and output is now buffered.
[...]
The proram is embarrassingly small but I cannot stop the print buffer.

[program snipped]

Your program works fine on Debian Lenny. To test, invoke it like this:

$ ./john | cat

It will wait after each "<br>".

hp

Thank you gentlemen

OK, I have run it from the command line and it is fine. The program waits
the required number of seconds and prints the next line.

But it does not work on a browser (IE6 IE7 and FF).

This probably (?) suggests Per 5.10 is OK and there is a setting in Apache2
that is causing the output to buffer.

Is that how you now see it?

Regards
John
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top