I've had expected results with a .pl script that had $|=1 in it running through mod_perl2, up until a recent fresh RedHat EL 5 installation where I had to reinstall my environment/software (via yum / rpms). Here is some environment-related info: Embedded Perl version v5.8.8 for Apache/2.2.3 (mod_perl v2.0.4) ... all x86_64.

/etc/httpd/conf.d/perl.conf:

LoadModule perl_module modules/mod_perl.so PerlRequire "/etc/httpd/mod_perl-startup.pl" Alias /perl/ "/var/www/cgi-bin/" <Directory /var/www/cgi-bin> SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI </Directory>

/etc/httpd/mod_perl-startup.pl:

if ( ! $ENV{MOD_PERL}) { die "GATEWAY_INTERFACE not Perl!"; } use lib qw(/usr/local/lib); use ModPerl::Util (); #for CORE::GLOBAL::exit use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::RequestUtil (); use Apache2::ServerRec (); use Apache2::ServerUtil (); use Apache2::Connection (); use Apache2::Log (); use APR::Table (); use ModPerl::Registry (); use Apache2::Const -compile => ':common'; use APR::Const -compile => ':common'; 1;

The test script being accessed via Firefox/IE (doesn't matter what browser):

#!/usr/bin/perl -W use strict; print "Content-type: text/html\n\n"; $|=1; for (my $x=1; $x<=10; $x++) { print($x); sleep 1; } exit(0);

Apache starts normally... all other functions that I've used in the mod_perl environment work as expected... The $|=1 command doesn't do anything--printing still behaves in a buffered manner. I have a similar installation in RHEL 4 where unbuffered printing works as expected (via $|=1). I found a few interesting posts on Google... first, this one: http://www.nntp.perl.org/group/perl.beginners.cgi/2006/07/msg12693.html, which basically describes that perl's STDOUT is redirected to Socket. Looking at the mod_perl2 documentation (http://perl.apache.org/docs/2.0/api/Apache2/RequestIO.html#C_print_, it references setting $|=1 as one would expect to create the desired unbuffered behavior.

What am I missing... I feel like it's some configuration within mod_perl itself (mod_perl-startup.pl / perl.conf) or Apache's config (httpd.conf)? Any help is GREATLY appreciated! Thank you in advance, and please let me know if additional environment info is needed...


In reply to mod_perl2 unbuffered printing by cappaberra

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.