ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-mod_perl
perl-mod_perl
mod_perl2 STDOUT question
by Niels Larsen other posts by this author
Aug 20 2008 8:30AM messages near this date
RE: mp2 + SOAP - SOAP calls fail randomly | Re: mod_perl2 STDOUT question
Greetings,

I have moved a big collection of modules to mod_perl2 under PerlRun
and can see a great speedup, as hoped. But in some of these modules
programs are run that write something to STDOUT that is then captured
and processed - which doesnt work since STDOUT is tie'ed to Apache.
I saw suggestions to use the $r->  interface, but I prefer to not be
mod_perl specific (write handlers or use the request object etc), at
least not until later. So to "borrow" STDOUT temporarily I did the
attempt below (found in Stas Bekmans 1.0 practical mod_perl), which
opens a temporary STDOUT into a string. Printing to STDOUT works as
hoped, but output from other programs run by system do not appear
in $out_str; instead they appear - most of the time, sometimes not -
in the console where Apache was started (with httpd -X). I can put
the command line to run in backticks and do print `@command`, and
that too works, but would like to use system, Proc::SafeExec, etc.
I use Apache 2.2.9, mod_perl 2.0.4 and Linux. Below the example is
the mod_perl part of httpd.conf.

Any ideas? (I'm sure its something obvious i missed, but it has
become an obstacle for me)

Niels L

------------------------------ test.cgi
<pre> 

#!/usr/bin/env perl

use strict;
use warnings FATAL =>  qw ( all );

use Symbol;

my ( $out_fh, $out_str );

{
     $out_str = "";

     $out_fh = Symbol::gensym();
     open $out_fh, '> ', \$out_str or die "Can't open stdout to string: $!";

     $| = 1;

     local *STDOUT = $out_fh;

     # Print always puts output into always goes into $out_str,
     print "hello\n";

     # But commands like date, ls etc goes into $out_str sometimes,
     # sometimes at console where apache was started with httpd -X
#    system( "date" );
     # print `date`;  # works

     close $out_fh;
}

#print "Content-type: text/html\n\n";
print "<pre> \n";
print $out_str;
print "</pre> \n";

print $ENV{"MOD_PERL"} ."<br> ";
print $ENV{"GATEWAY_INTERFACE"} ."<br> ";
print $ENV{"SERVER_PROTOCOL"} ."<br> ";

</pre> 

--------------- httpd.conf

SetEnv TERM "dumb"
PerlSetEnv TERM "dumb"

LoadModule perl_module modules/mod_perl.so
PerlModule ModPerl::PerlRun

<LocationMatch "/test.cgi"> 
     SetHandler perl-script
     PerlResponseHandler ModPerl::PerlRun
     Options SymLinksifOwnerMatch ExecCGI
</LocationMatch> 
Thread:
Niels Larsen
Perrin Harkins
Eric Berg
Jim Brandt

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved