Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > print buffer in Perl 5.10

Reply
Thread Tools

print buffer in Perl 5.10

 
 
John
Guest
Posts: n/a
 
      06-03-2009
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



 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      06-04-2009

"Ben Morrow" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Quoth "John" <(E-Mail Removed)>:
>>
>> 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.

>
> 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



 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      06-04-2009
In article <h0850t$q2j$(E-Mail Removed)>, John <(E-Mail Removed)>
wrote:

> "Ben Morrow" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >
> > Quoth "John" <(E-Mail Removed)>:
> >>
> >> 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.

> >
> > 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.


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.

--
Jim Gibson
 
Reply With Quote
 
John
Guest
Posts: n/a
 
      06-04-2009

"Jim Gibson" <(E-Mail Removed)> wrote in message
news:040620090919280377%(E-Mail Removed)...
> In article <h0850t$q2j$(E-Mail Removed)>, John <(E-Mail Removed)>
> wrote:
>
>> "Ben Morrow" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >
>> > Quoth "John" <(E-Mail Removed)>:
>> >>
>> >> 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.
>> >
>> > 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.

>
> 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.
>
> --
> 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.

Regards
John



 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      06-04-2009
In article <h08sjh$rgb$(E-Mail Removed)>, John <(E-Mail Removed)>
wrote:

> "Jim Gibson" <(E-Mail Removed)> wrote in message
> news:040620090919280377%(E-Mail Removed)...
> > In article <h0850t$q2j$(E-Mail Removed)>, John <(E-Mail Removed)>
> > wrote:
> >


> > #!/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.


> 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>

--
Jim Gibson
 
Reply With Quote
 
Peter J. Holzer
Guest
Posts: n/a
 
      06-04-2009
On 2009-06-04 09:44, John <(E-Mail Removed)> wrote:
>
> "Ben Morrow" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>
>> Quoth "John" <(E-Mail Removed)>:
>>>
>>> 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

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      06-05-2009

"Peter J. Holzer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On 2009-06-04 09:44, John <(E-Mail Removed)> wrote:
>>
>> "Ben Morrow" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>
>>> Quoth "John" <(E-Mail Removed)>:
>>>>
>>>> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
buffer creates only read-only buffer? Neal Becker Python 0 01-08-2009 01:58 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net 2 07-29-2008 09:50 AM
When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 bytes get flushed on seek and the buffer become a readbuffer at that point instead of being a write buffer? DR ASP .Net Building Controls 0 07-29-2008 01:37 AM
convert M bit buffer to N bit buffer runcyclexcski@yahoo.com C++ 2 03-26-2007 09:43 AM
How to know the buffer size and increase buffer size in c++ Raja C++ 12 06-21-2004 06:21 PM



Advertisments