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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |