You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Steven Haigh via modperl <mo...@perl.apache.org> on 2024/05/13 06:53:32 UTC

stdout from scripts goes to apache logs

Hi all,

I'm playing around with mod_perl on apache on docker - and now I've 
finally got all the module issues sorted, I'm trying to figure out why 
when using mod_perl, the output of scripts ends up in the apache logs.

The following configuration works, and the output of shelled scripts 
works as expected:

<Location />
     DirectoryIndex index.pl index.html
     AddHandler cgi-script .pl
     Options +Indexes +FollowSymLinks +ExecCGI
     Require all granted
</Location>

If I change this to use mod_perl, all output from scripts run in web 
pages ends up in the apache log:

<Location />
     DirectoryIndex index.pl index.html
     AddHandler perl-script .pl
     Options +Indexes +FollowSymLinks +ExecCGI
     Require all granted
</Location>

The perl code I'm using in the web page is as follows:
my $cmd = "/bin/stdbuf";
my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;

print '<pre class="alert">';
my $pid = open3(0, \*READER, 0, $cmd, @args);
while ( my $output = <READER> ) {
     print $output;
}
print "Speed test complete.</pre>";
waitpid $pid,0;

Does anyone have any clues as to why STDOUT would end up in the apache 
log and not in the web page being served when using perl-script as the 
handler?

-- 
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au



RE: stdout from scripts goes to apache logs

Posted by David Cook via modperl <mo...@perl.apache.org>.
I can't speak to your exact situation, but for what it's worth...

In Plack environments, I use IPC::Open3. In mod_perl environments, I use Apache2::SubProcess. 

If you have a Apache2::RequestRec object, you can then do something like this:
($child_in, $child_out, $child_err) = $r->spawn_proc_prog($script,$script_args);

(I have a particular context with an older Catalyst where I had to use a custom PSGI middleware to save the Apache2::RequestRec object for later reuse, as POST/PUT requests were discarding it, but where there's a will there's a way...)

I don't know if I'd choose mod_perl for a new project, but I still use it for some older ones and it's pretty good. 

David Cook
Senior Software Engineer
Prosentient Systems

-----Original Message-----
From: Steven Haigh via modperl <mo...@perl.apache.org> 
Sent: Tuesday, 14 May 2024 2:45 PM
To: modperl@perl.apache.org
Subject: Re: stdout from scripts goes to apache logs

On 14/5/24 14:18, Ed Sabol wrote:
> On May 13, 2024, at 11:00 PM, Steven Haigh via modperl <mo...@perl.apache.org> wrote:
>> If I was to guess, it seems like an interaction with open3 and modperl.
>>
>> https://perldoc.perl.org/IPC::Open3
> 
> Yes, this is a known problem with IPC::Open3 that is commonly seen 
> with mod_perl. It's been a Perl bug since 2009, and nobody has 
> apparently been interested in fixing it. :(
> 
> https://github.com/Perl/perl5/issues/9759

Damn, that's interesting to find out... and annoying :)

> So I think you just need to work around it. I recommend not using IPC::Open3 in any mod_perl projects. I typically just use backticks and redirect stderr to stdout or to a temp file, but sometimes you just need separate filehandles. For that, I offer the following potential workarounds that you can try:
> 
> (1) Use IPC::Run instead of IPC::Open3. I've seen at least one report that says that IPC::Run works well in mod_perl, and it can do similar things.
> 
> https://metacpan.org/pod/IPC::Run

I did have some success with IPC::Run - and that does seem to work as expected - however I hit buffering issues that I didn't see when using the open3 code.

One of the tools I use this code with is a looking glass - so you can perform traceroutes to various places.

With using cgi-script + open3, this is returned line by line to the browser - which is really nice.

Using IPC::Run, you get no output until the traceroute has completed.

I haven't spent a ton of time to see if that buffering can be altered in IPC::Run as yet, but either way, it becomes a less-optimal result to just blat the entire traceroute to the screen at once.

It can take quite a while for a traceroute to complete if theres 20+ hops that don't respond - which means you get no output at all until its done.

> (2) Re-jigger the file descriptors as shown here:
> 
> https://stackoverflow.com/questions/2097247/ipcopen3-fails-running-und
> er-apache/24311232#24311232

I did try this, but the output still went to the apache logs.

For the traceroute example, I tried this code:

         my $cmd = "/usr/bin/stdbuf";
         my @args = qw@ -o1 -e1 /usr/bin/traceroute @;

         if ( $vars->{'type'} eq "ipv6" ) {
                 push @args,"-6";
         } else {
                 push @args,"-4";
         }

         push @args, $vars->{"host"};

         print '<pre class="alert">';
	my ($save_stdin,$save_stdout);
	open $save_stdin, '>&STDIN';
	open $save_stdout, '>&STDOUT';
	open STDIN, '>&=0';
	open STDOUT, '>&=1';

         my $pid = open3(0, (my $pipe = gensym), 0, $cmd, @args);
         while ( my $output = <$pipe> ) {
                 print $output;
         }

	close(STDIN);
	close(STDOUT);
	open STDIN, '>&', $save_stdin;
	open STDOUT, '>&', $save_stdout;
         print "Trace Complete</pre>";

This still printed the output to the apache logs, along with an error:

Warning: unable to close filehandle $save_stdin properly:  at /var/www/html/lg/index.pl line 66.

I'm starting to wonder that if with the various 'strange' behaviours, it might be easier to not use mod_perl for this and keep using the cgi-script handler. It isn't a high performance or popular site at all - I've been using it more as a learning exercise - but I'm wondering if the benefits of using mod_perl here are purely academic :)


--
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au


Re: stdout from scripts goes to apache logs

Posted by Steven Haigh via modperl <mo...@perl.apache.org>.
On 14/5/24 14:18, Ed Sabol wrote:
> On May 13, 2024, at 11:00 PM, Steven Haigh via modperl <mo...@perl.apache.org> wrote:
>> If I was to guess, it seems like an interaction with open3 and modperl.
>>
>> https://perldoc.perl.org/IPC::Open3
> 
> Yes, this is a known problem with IPC::Open3 that is commonly seen with mod_perl. It's been a Perl bug since 2009, and nobody has apparently been interested in fixing it. :(
> 
> https://github.com/Perl/perl5/issues/9759

Damn, that's interesting to find out... and annoying :)

> So I think you just need to work around it. I recommend not using IPC::Open3 in any mod_perl projects. I typically just use backticks and redirect stderr to stdout or to a temp file, but sometimes you just need separate filehandles. For that, I offer the following potential workarounds that you can try:
> 
> (1) Use IPC::Run instead of IPC::Open3. I've seen at least one report that says that IPC::Run works well in mod_perl, and it can do similar things.
> 
> https://metacpan.org/pod/IPC::Run

I did have some success with IPC::Run - and that does seem to work as 
expected - however I hit buffering issues that I didn't see when using 
the open3 code.

One of the tools I use this code with is a looking glass - so you can 
perform traceroutes to various places.

With using cgi-script + open3, this is returned line by line to the 
browser - which is really nice.

Using IPC::Run, you get no output until the traceroute has completed.

I haven't spent a ton of time to see if that buffering can be altered in 
IPC::Run as yet, but either way, it becomes a less-optimal result to 
just blat the entire traceroute to the screen at once.

It can take quite a while for a traceroute to complete if theres 20+ 
hops that don't respond - which means you get no output at all until its 
done.

> (2) Re-jigger the file descriptors as shown here:
> 
> https://stackoverflow.com/questions/2097247/ipcopen3-fails-running-under-apache/24311232#24311232

I did try this, but the output still went to the apache logs.

For the traceroute example, I tried this code:

         my $cmd = "/usr/bin/stdbuf";
         my @args = qw@ -o1 -e1 /usr/bin/traceroute @;

         if ( $vars->{'type'} eq "ipv6" ) {
                 push @args,"-6";
         } else {
                 push @args,"-4";
         }

         push @args, $vars->{"host"};

         print '<pre class="alert">';
	my ($save_stdin,$save_stdout);
	open $save_stdin, '>&STDIN';
	open $save_stdout, '>&STDOUT';
	open STDIN, '>&=0';
	open STDOUT, '>&=1';

         my $pid = open3(0, (my $pipe = gensym), 0, $cmd, @args);
         while ( my $output = <$pipe> ) {
                 print $output;
         }

	close(STDIN);
	close(STDOUT);
	open STDIN, '>&', $save_stdin;
	open STDOUT, '>&', $save_stdout;
         print "Trace Complete</pre>";

This still printed the output to the apache logs, along with an error:

Warning: unable to close filehandle $save_stdin properly:  at 
/var/www/html/lg/index.pl line 66.

I'm starting to wonder that if with the various 'strange' behaviours, it 
might be easier to not use mod_perl for this and keep using the 
cgi-script handler. It isn't a high performance or popular site at all - 
I've been using it more as a learning exercise - but I'm wondering if 
the benefits of using mod_perl here are purely academic :)


-- 
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au


Re: stdout from scripts goes to apache logs

Posted by Ed Sabol <ed...@gmail.com>.
On May 13, 2024, at 11:00 PM, Steven Haigh via modperl <mo...@perl.apache.org> wrote:
> If I was to guess, it seems like an interaction with open3 and modperl.
> 
> https://perldoc.perl.org/IPC::Open3

Yes, this is a known problem with IPC::Open3 that is commonly seen with mod_perl. It's been a Perl bug since 2009, and nobody has apparently been interested in fixing it. :(

https://github.com/Perl/perl5/issues/9759

So I think you just need to work around it. I recommend not using IPC::Open3 in any mod_perl projects. I typically just use backticks and redirect stderr to stdout or to a temp file, but sometimes you just need separate filehandles. For that, I offer the following potential workarounds that you can try:

(1) Use IPC::Run instead of IPC::Open3. I've seen at least one report that says that IPC::Run works well in mod_perl, and it can do similar things.

https://metacpan.org/pod/IPC::Run

(2) Re-jigger the file descriptors as shown here:

https://stackoverflow.com/questions/2097247/ipcopen3-fails-running-under-apache/24311232#24311232

Hope this helps,
Ed


Re: stdout from scripts goes to apache logs

Posted by Steven Haigh via modperl <mo...@perl.apache.org>.
The apache config for modperl is as follows:

## Load mod_perl
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
PerlOptions +Parent
PerlSwitches -Mlib=/var/www/includes

<Location />
         DirectoryIndex index.pl index.html
         #AddHandler cgi-script .pl
         AddHandler perl-script .pl
         PerlResponseHandler ModPerl::Registry
         Options Indexes FollowSymLinks ExecCGI
         Require all granted
</Location>

To test between the two options, I change the comment for AddHandler.

On 14/5/24 13:21, Joseph He wrote:
> Steven, how do you put your script under the mod-perl environment? What 
> is your httpd.conf file? Thx.
> 
> 
> On Mon, May 13, 2024 at 10:00 PM Steven Haigh via modperl 
> <modperl@perl.apache.org <ma...@perl.apache.org>> wrote:
> 
>     I wonder if perhaps I haven't been clear in the problem.
> 
>     In the provided code example:
>            my $cmd = "/bin/stdbuf";
>            my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
> 
>            print '<pre class="alert">';    <-- appears in the HTML output.
>            my $pid = open3(0, \*READER, 0, $cmd, @args);
>            while ( my $output = <READER> ) {
>                  print $output;      <-- This never outputs anything.
>            }
>            print "Speed test complete.</pre>"; <-- appears in the HTML
>     output.
>            waitpid $pid,0;
> 
>     If I was to guess, it seems like an interaction with open3 and modperl.
> 
>     https://perldoc.perl.org/IPC::Open3
>     <https://perldoc.perl.org/IPC::Open3>
> 
>     The syntax is basically:
> 
>     my $pid = open3( <input>, <stdout>, <stderr>, $cmd, @args );
> 
>     If I understand it right, I give it a filehandle - which I then read
>     from. The executed command is then:
> 
>     /bin/stdbuf -o1 -e1 /usr/bin/speedtest-cli
> 
>     The inclusion of using stdbuf with these options are to stream the
>     ouput
>     line after line, and not whatever terminal buffer is in place that will
>     return the output in a chunk.
> 
>     However, all output from running the command ends up in the apache logs.
> 
>     That means that <READER> never gets anything, and therefore the
>     print is
>     never called.
> 
>     Does that make more sense?
> 
> 
>     On 14/5/24 12:46, Joseph He wrote:
>      > Steven, you need to use those mod-perl libraries to handle the web
>      > request and to generate the response.
>      >
>      > https://perl.apache.org/docs/2.0/user/intro/start_fast.html
>     <https://perl.apache.org/docs/2.0/user/intro/start_fast.html>
>      > <https://perl.apache.org/docs/2.0/user/intro/start_fast.html
>     <https://perl.apache.org/docs/2.0/user/intro/start_fast.html>>
>      >
>      > Scroll down to the bottom, you can see how to output the content.
>      >
>      > Cheers,
>      > Joseph
>      >
>      >
>      > On Mon, May 13, 2024 at 9:35 PM Steven Haigh via modperl
>      > <modperl@perl.apache.org <ma...@perl.apache.org>
>     <mailto:modperl@perl.apache.org <ma...@perl.apache.org>>>
>     wrote:
>      >
>      >     That being said, is there a way to output to the web page in this
>      >     scenario?
>      >
>      >     On 14/5/24 12:15, Joseph He wrote:
>      >      > CGI script runs on its own process. mod-perl basically
>     wraps CGI
>      >     script
>      >      > into apache process, that is why its output is automatically
>      >     going to
>      >      > Apache log.
>      >      >
>      >      > On Mon, May 13, 2024 at 1:53 AM Steven Haigh via modperl
>      >      > <modperl@perl.apache.org <ma...@perl.apache.org>
>     <mailto:modperl@perl.apache.org <ma...@perl.apache.org>>
>      >     <mailto:modperl@perl.apache.org
>     <ma...@perl.apache.org> <mailto:modperl@perl.apache.org
>     <ma...@perl.apache.org>>>>
>      >     wrote:
>      >      >
>      >      >     Hi all,
>      >      >
>      >      >     I'm playing around with mod_perl on apache on docker - and
>      >     now I've
>      >      >     finally got all the module issues sorted, I'm trying to
>      >     figure out why
>      >      >     when using mod_perl, the output of scripts ends up in the
>      >     apache logs.
>      >      >
>      >      >     The following configuration works, and the output of
>     shelled
>      >     scripts
>      >      >     works as expected:
>      >      >
>      >      >     <Location />
>      >      >           DirectoryIndex index.pl <http://index.pl>
>     <http://index.pl <http://index.pl>>
>      >     <http://index.pl <http://index.pl> <http://index.pl
>     <http://index.pl>>> index.html
>      >      >           AddHandler cgi-script .pl
>      >      >           Options +Indexes +FollowSymLinks +ExecCGI
>      >      >           Require all granted
>      >      >     </Location>
>      >      >
>      >      >     If I change this to use mod_perl, all output from
>     scripts run
>      >     in web
>      >      >     pages ends up in the apache log:
>      >      >
>      >      >     <Location />
>      >      >           DirectoryIndex index.pl <http://index.pl>
>     <http://index.pl <http://index.pl>>
>      >     <http://index.pl <http://index.pl> <http://index.pl
>     <http://index.pl>>> index.html
>      >      >           AddHandler perl-script .pl
>      >      >           Options +Indexes +FollowSymLinks +ExecCGI
>      >      >           Require all granted
>      >      >     </Location>
>      >      >
>      >      >     The perl code I'm using in the web page is as follows:
>      >      >     my $cmd = "/bin/stdbuf";
>      >      >     my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
>      >      >
>      >      >     print '<pre class="alert">';
>      >      >     my $pid = open3(0, \*READER, 0, $cmd, @args);
>      >      >     while ( my $output = <READER> ) {
>      >      >           print $output;
>      >      >     }
>      >      >     print "Speed test complete.</pre>";
>      >      >     waitpid $pid,0;
>      >      >
>      >      >     Does anyone have any clues as to why STDOUT would end
>     up in
>      >     the apache
>      >      >     log and not in the web page being served when using
>      >     perl-script as the
>      >      >     handler?
>      >      >
>      >      >     --
>      >      >     Steven Haigh
>      >      >
>      >      >     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     <mailto:netwiz@crc.id.au <ma...@crc.id.au>>
>      >     <mailto:netwiz@crc.id.au <ma...@crc.id.au>
>     <mailto:netwiz@crc.id.au <ma...@crc.id.au>>>
>      >      >     💻 https://crc.id.au <https://crc.id.au>
>     <https://crc.id.au <https://crc.id.au>> <https://crc.id.au
>     <https://crc.id.au>
>      >     <https://crc.id.au <https://crc.id.au>>>
>      >      >
>      >      >
>      >
>      >     --
>      >     Steven Haigh
>      >
>      >     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     <mailto:netwiz@crc.id.au <ma...@crc.id.au>>
>      >     💻 https://crc.id.au <https://crc.id.au> <https://crc.id.au
>     <https://crc.id.au>>
>      >
> 
>     -- 
>     Steven Haigh
> 
>     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     💻 https://crc.id.au <https://crc.id.au>
> 

-- 
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au


Re: stdout from scripts goes to apache logs

Posted by Joseph He <jo...@gmail.com>.
Steven, how do you put your script under the mod-perl environment? What is
your httpd.conf file? Thx.


On Mon, May 13, 2024 at 10:00 PM Steven Haigh via modperl <
modperl@perl.apache.org> wrote:

> I wonder if perhaps I haven't been clear in the problem.
>
> In the provided code example:
>       my $cmd = "/bin/stdbuf";
>       my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
>
>       print '<pre class="alert">';    <-- appears in the HTML output.
>       my $pid = open3(0, \*READER, 0, $cmd, @args);
>       while ( my $output = <READER> ) {
>             print $output;      <-- This never outputs anything.
>       }
>       print "Speed test complete.</pre>"; <-- appears in the HTML output.
>       waitpid $pid,0;
>
> If I was to guess, it seems like an interaction with open3 and modperl.
>
> https://perldoc.perl.org/IPC::Open3
>
> The syntax is basically:
>
> my $pid = open3( <input>, <stdout>, <stderr>, $cmd, @args );
>
> If I understand it right, I give it a filehandle - which I then read
> from. The executed command is then:
>
> /bin/stdbuf -o1 -e1 /usr/bin/speedtest-cli
>
> The inclusion of using stdbuf with these options are to stream the ouput
> line after line, and not whatever terminal buffer is in place that will
> return the output in a chunk.
>
> However, all output from running the command ends up in the apache logs.
>
> That means that <READER> never gets anything, and therefore the print is
> never called.
>
> Does that make more sense?
>
>
> On 14/5/24 12:46, Joseph He wrote:
> > Steven, you need to use those mod-perl libraries to handle the web
> > request and to generate the response.
> >
> > https://perl.apache.org/docs/2.0/user/intro/start_fast.html
> > <https://perl.apache.org/docs/2.0/user/intro/start_fast.html>
> >
> > Scroll down to the bottom, you can see how to output the content.
> >
> > Cheers,
> > Joseph
> >
> >
> > On Mon, May 13, 2024 at 9:35 PM Steven Haigh via modperl
> > <modperl@perl.apache.org <ma...@perl.apache.org>> wrote:
> >
> >     That being said, is there a way to output to the web page in this
> >     scenario?
> >
> >     On 14/5/24 12:15, Joseph He wrote:
> >      > CGI script runs on its own process. mod-perl basically wraps CGI
> >     script
> >      > into apache process, that is why its output is automatically
> >     going to
> >      > Apache log.
> >      >
> >      > On Mon, May 13, 2024 at 1:53 AM Steven Haigh via modperl
> >      > <modperl@perl.apache.org <ma...@perl.apache.org>
> >     <mailto:modperl@perl.apache.org <ma...@perl.apache.org>>>
> >     wrote:
> >      >
> >      >     Hi all,
> >      >
> >      >     I'm playing around with mod_perl on apache on docker - and
> >     now I've
> >      >     finally got all the module issues sorted, I'm trying to
> >     figure out why
> >      >     when using mod_perl, the output of scripts ends up in the
> >     apache logs.
> >      >
> >      >     The following configuration works, and the output of shelled
> >     scripts
> >      >     works as expected:
> >      >
> >      >     <Location />
> >      >           DirectoryIndex index.pl <http://index.pl>
> >     <http://index.pl <http://index.pl>> index.html
> >      >           AddHandler cgi-script .pl
> >      >           Options +Indexes +FollowSymLinks +ExecCGI
> >      >           Require all granted
> >      >     </Location>
> >      >
> >      >     If I change this to use mod_perl, all output from scripts run
> >     in web
> >      >     pages ends up in the apache log:
> >      >
> >      >     <Location />
> >      >           DirectoryIndex index.pl <http://index.pl>
> >     <http://index.pl <http://index.pl>> index.html
> >      >           AddHandler perl-script .pl
> >      >           Options +Indexes +FollowSymLinks +ExecCGI
> >      >           Require all granted
> >      >     </Location>
> >      >
> >      >     The perl code I'm using in the web page is as follows:
> >      >     my $cmd = "/bin/stdbuf";
> >      >     my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
> >      >
> >      >     print '<pre class="alert">';
> >      >     my $pid = open3(0, \*READER, 0, $cmd, @args);
> >      >     while ( my $output = <READER> ) {
> >      >           print $output;
> >      >     }
> >      >     print "Speed test complete.</pre>";
> >      >     waitpid $pid,0;
> >      >
> >      >     Does anyone have any clues as to why STDOUT would end up in
> >     the apache
> >      >     log and not in the web page being served when using
> >     perl-script as the
> >      >     handler?
> >      >
> >      >     --
> >      >     Steven Haigh
> >      >
> >      >     📧 netwiz@crc.id.au <ma...@crc.id.au>
> >     <mailto:netwiz@crc.id.au <ma...@crc.id.au>>
> >      >     💻 https://crc.id.au <https://crc.id.au> <https://crc.id.au
> >     <https://crc.id.au>>
> >      >
> >      >
> >
> >     --
> >     Steven Haigh
> >
> >     📧 netwiz@crc.id.au <ma...@crc.id.au>
> >     💻 https://crc.id.au <https://crc.id.au>
> >
>
> --
> Steven Haigh
>
> 📧 netwiz@crc.id.au
> 💻 https://crc.id.au
>
>

Re: stdout from scripts goes to apache logs

Posted by Steven Haigh via modperl <mo...@perl.apache.org>.
I wonder if perhaps I haven't been clear in the problem.

In the provided code example:
      my $cmd = "/bin/stdbuf";
      my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;

      print '<pre class="alert">';    <-- appears in the HTML output.
      my $pid = open3(0, \*READER, 0, $cmd, @args);
      while ( my $output = <READER> ) {
            print $output;	<-- This never outputs anything.
      }
      print "Speed test complete.</pre>"; <-- appears in the HTML output.
      waitpid $pid,0;

If I was to guess, it seems like an interaction with open3 and modperl.

https://perldoc.perl.org/IPC::Open3

The syntax is basically:

my $pid = open3( <input>, <stdout>, <stderr>, $cmd, @args );

If I understand it right, I give it a filehandle - which I then read 
from. The executed command is then:

/bin/stdbuf -o1 -e1 /usr/bin/speedtest-cli

The inclusion of using stdbuf with these options are to stream the ouput 
line after line, and not whatever terminal buffer is in place that will 
return the output in a chunk.

However, all output from running the command ends up in the apache logs.

That means that <READER> never gets anything, and therefore the print is 
never called.

Does that make more sense?


On 14/5/24 12:46, Joseph He wrote:
> Steven, you need to use those mod-perl libraries to handle the web 
> request and to generate the response.
> 
> https://perl.apache.org/docs/2.0/user/intro/start_fast.html 
> <https://perl.apache.org/docs/2.0/user/intro/start_fast.html>
> 
> Scroll down to the bottom, you can see how to output the content.
> 
> Cheers,
> Joseph
> 
> 
> On Mon, May 13, 2024 at 9:35 PM Steven Haigh via modperl 
> <modperl@perl.apache.org <ma...@perl.apache.org>> wrote:
> 
>     That being said, is there a way to output to the web page in this
>     scenario?
> 
>     On 14/5/24 12:15, Joseph He wrote:
>      > CGI script runs on its own process. mod-perl basically wraps CGI
>     script
>      > into apache process, that is why its output is automatically
>     going to
>      > Apache log.
>      >
>      > On Mon, May 13, 2024 at 1:53 AM Steven Haigh via modperl
>      > <modperl@perl.apache.org <ma...@perl.apache.org>
>     <mailto:modperl@perl.apache.org <ma...@perl.apache.org>>>
>     wrote:
>      >
>      >     Hi all,
>      >
>      >     I'm playing around with mod_perl on apache on docker - and
>     now I've
>      >     finally got all the module issues sorted, I'm trying to
>     figure out why
>      >     when using mod_perl, the output of scripts ends up in the
>     apache logs.
>      >
>      >     The following configuration works, and the output of shelled
>     scripts
>      >     works as expected:
>      >
>      >     <Location />
>      >           DirectoryIndex index.pl <http://index.pl>
>     <http://index.pl <http://index.pl>> index.html
>      >           AddHandler cgi-script .pl
>      >           Options +Indexes +FollowSymLinks +ExecCGI
>      >           Require all granted
>      >     </Location>
>      >
>      >     If I change this to use mod_perl, all output from scripts run
>     in web
>      >     pages ends up in the apache log:
>      >
>      >     <Location />
>      >           DirectoryIndex index.pl <http://index.pl>
>     <http://index.pl <http://index.pl>> index.html
>      >           AddHandler perl-script .pl
>      >           Options +Indexes +FollowSymLinks +ExecCGI
>      >           Require all granted
>      >     </Location>
>      >
>      >     The perl code I'm using in the web page is as follows:
>      >     my $cmd = "/bin/stdbuf";
>      >     my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
>      >
>      >     print '<pre class="alert">';
>      >     my $pid = open3(0, \*READER, 0, $cmd, @args);
>      >     while ( my $output = <READER> ) {
>      >           print $output;
>      >     }
>      >     print "Speed test complete.</pre>";
>      >     waitpid $pid,0;
>      >
>      >     Does anyone have any clues as to why STDOUT would end up in
>     the apache
>      >     log and not in the web page being served when using
>     perl-script as the
>      >     handler?
>      >
>      >     --
>      >     Steven Haigh
>      >
>      >     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     <mailto:netwiz@crc.id.au <ma...@crc.id.au>>
>      >     💻 https://crc.id.au <https://crc.id.au> <https://crc.id.au
>     <https://crc.id.au>>
>      >
>      >
> 
>     -- 
>     Steven Haigh
> 
>     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     💻 https://crc.id.au <https://crc.id.au>
> 

-- 
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au


Re: stdout from scripts goes to apache logs

Posted by Joseph He <jo...@gmail.com>.
Steven, you need to use those mod-perl libraries to handle the web request
and to generate the response.

https://perl.apache.org/docs/2.0/user/intro/start_fast.html

Scroll down to the bottom, you can see how to output the content.

Cheers,
Joseph


On Mon, May 13, 2024 at 9:35 PM Steven Haigh via modperl <
modperl@perl.apache.org> wrote:

> That being said, is there a way to output to the web page in this scenario?
>
> On 14/5/24 12:15, Joseph He wrote:
> > CGI script runs on its own process. mod-perl basically wraps CGI script
> > into apache process, that is why its output is automatically going to
> > Apache log.
> >
> > On Mon, May 13, 2024 at 1:53 AM Steven Haigh via modperl
> > <modperl@perl.apache.org <ma...@perl.apache.org>> wrote:
> >
> >     Hi all,
> >
> >     I'm playing around with mod_perl on apache on docker - and now I've
> >     finally got all the module issues sorted, I'm trying to figure out
> why
> >     when using mod_perl, the output of scripts ends up in the apache
> logs.
> >
> >     The following configuration works, and the output of shelled scripts
> >     works as expected:
> >
> >     <Location />
> >           DirectoryIndex index.pl <http://index.pl> index.html
> >           AddHandler cgi-script .pl
> >           Options +Indexes +FollowSymLinks +ExecCGI
> >           Require all granted
> >     </Location>
> >
> >     If I change this to use mod_perl, all output from scripts run in web
> >     pages ends up in the apache log:
> >
> >     <Location />
> >           DirectoryIndex index.pl <http://index.pl> index.html
> >           AddHandler perl-script .pl
> >           Options +Indexes +FollowSymLinks +ExecCGI
> >           Require all granted
> >     </Location>
> >
> >     The perl code I'm using in the web page is as follows:
> >     my $cmd = "/bin/stdbuf";
> >     my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
> >
> >     print '<pre class="alert">';
> >     my $pid = open3(0, \*READER, 0, $cmd, @args);
> >     while ( my $output = <READER> ) {
> >           print $output;
> >     }
> >     print "Speed test complete.</pre>";
> >     waitpid $pid,0;
> >
> >     Does anyone have any clues as to why STDOUT would end up in the
> apache
> >     log and not in the web page being served when using perl-script as
> the
> >     handler?
> >
> >     --
> >     Steven Haigh
> >
> >     📧 netwiz@crc.id.au <ma...@crc.id.au>
> >     💻 https://crc.id.au <https://crc.id.au>
> >
> >
>
> --
> Steven Haigh
>
> 📧 netwiz@crc.id.au
> 💻 https://crc.id.au
>
>

Re: stdout from scripts goes to apache logs

Posted by Steven Haigh via modperl <mo...@perl.apache.org>.
That being said, is there a way to output to the web page in this scenario?

On 14/5/24 12:15, Joseph He wrote:
> CGI script runs on its own process. mod-perl basically wraps CGI script 
> into apache process, that is why its output is automatically going to 
> Apache log.
> 
> On Mon, May 13, 2024 at 1:53 AM Steven Haigh via modperl 
> <modperl@perl.apache.org <ma...@perl.apache.org>> wrote:
> 
>     Hi all,
> 
>     I'm playing around with mod_perl on apache on docker - and now I've
>     finally got all the module issues sorted, I'm trying to figure out why
>     when using mod_perl, the output of scripts ends up in the apache logs.
> 
>     The following configuration works, and the output of shelled scripts
>     works as expected:
> 
>     <Location />
>           DirectoryIndex index.pl <http://index.pl> index.html
>           AddHandler cgi-script .pl
>           Options +Indexes +FollowSymLinks +ExecCGI
>           Require all granted
>     </Location>
> 
>     If I change this to use mod_perl, all output from scripts run in web
>     pages ends up in the apache log:
> 
>     <Location />
>           DirectoryIndex index.pl <http://index.pl> index.html
>           AddHandler perl-script .pl
>           Options +Indexes +FollowSymLinks +ExecCGI
>           Require all granted
>     </Location>
> 
>     The perl code I'm using in the web page is as follows:
>     my $cmd = "/bin/stdbuf";
>     my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
> 
>     print '<pre class="alert">';
>     my $pid = open3(0, \*READER, 0, $cmd, @args);
>     while ( my $output = <READER> ) {
>           print $output;
>     }
>     print "Speed test complete.</pre>";
>     waitpid $pid,0;
> 
>     Does anyone have any clues as to why STDOUT would end up in the apache
>     log and not in the web page being served when using perl-script as the
>     handler?
> 
>     -- 
>     Steven Haigh
> 
>     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     💻 https://crc.id.au <https://crc.id.au>
> 
> 

-- 
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au


Re: stdout from scripts goes to apache logs

Posted by Joseph He <jo...@gmail.com>.
CGI script runs on its own process. mod-perl basically wraps CGI script
into apache process, that is why its output is automatically going to
Apache log.

On Mon, May 13, 2024 at 1:53 AM Steven Haigh via modperl <
modperl@perl.apache.org> wrote:

> Hi all,
>
> I'm playing around with mod_perl on apache on docker - and now I've
> finally got all the module issues sorted, I'm trying to figure out why
> when using mod_perl, the output of scripts ends up in the apache logs.
>
> The following configuration works, and the output of shelled scripts
> works as expected:
>
> <Location />
>      DirectoryIndex index.pl index.html
>      AddHandler cgi-script .pl
>      Options +Indexes +FollowSymLinks +ExecCGI
>      Require all granted
> </Location>
>
> If I change this to use mod_perl, all output from scripts run in web
> pages ends up in the apache log:
>
> <Location />
>      DirectoryIndex index.pl index.html
>      AddHandler perl-script .pl
>      Options +Indexes +FollowSymLinks +ExecCGI
>      Require all granted
> </Location>
>
> The perl code I'm using in the web page is as follows:
> my $cmd = "/bin/stdbuf";
> my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
>
> print '<pre class="alert">';
> my $pid = open3(0, \*READER, 0, $cmd, @args);
> while ( my $output = <READER> ) {
>      print $output;
> }
> print "Speed test complete.</pre>";
> waitpid $pid,0;
>
> Does anyone have any clues as to why STDOUT would end up in the apache
> log and not in the web page being served when using perl-script as the
> handler?
>
> --
> Steven Haigh
>
> 📧 netwiz@crc.id.au
> 💻 https://crc.id.au
>
>
>

Re: Re: stdout from scripts goes to apache logs

Posted by Vincent Veyron <vv...@wanadoo.fr>.
Hi Steven,

I don't work with registry scripts, so can't help with that, but I thought I'd mention a change I noticed in the way Apache2 handles STDERR output : it stopped obeying the ErrorLog configuration directives that I use for the few web sites I maintain. It now sends error messages to the default errorlog file, or to the errorlog file of one of the websites, depending on whether I enable the directive or not in it. 

Something is amiss, I haven't found out what. This used to work, the change seems to have happened when I upgraded to Debian Bookworm.

 

-- 
					Bien à vous, Vincent Veyron 

https://marica.fr/ 
Logiciel de suivi des contentieux juridiques, des sinistres d'assurance et des contrats



Re: stdout from scripts goes to apache logs

Posted by Steven Haigh via modperl <mo...@perl.apache.org>.
Hi Ian,

You're right - I did actually copy just one of the iterations I've tried 
of apache config.

The parts of httpd.conf that I've added are:

## Load mod_perl
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
PerlOptions +Parent
PerlSwitches -Mlib=/var/www/includes

<Location />
         DirectoryIndex index.pl index.html
         AddHandler perl-script .pl
         PerlResponseHandler ModPerl::Registry
         Options Indexes FollowSymLinks ExecCGI
         Require all granted
</Location>

This has the same symptoms however.

In this same configuration, changing the Handler from perl-script to 
cgi-script restores the expected behaviour...

On 13/5/24 19:14, Ian B wrote:
> Not an expert here, so someone I'm sure will correct me if wrong!
> 
> Normally I'd expect an actual PerlHandler or similar included, eg 
> PerlHandler ModPerl::Registry   or PerlHandler SomeLib::SomePAckage type 
> thing...
> (this would be as well as the Set/AddHandler line)
> 
> Kind regards,
> 
> On Mon, May 13, 2024 at 7:54 AM Steven Haigh via modperl 
> <modperl@perl.apache.org <ma...@perl.apache.org>> wrote:
> 
>     Hi all,
> 
>     I'm playing around with mod_perl on apache on docker - and now I've
>     finally got all the module issues sorted, I'm trying to figure out why
>     when using mod_perl, the output of scripts ends up in the apache logs.
> 
>     The following configuration works, and the output of shelled scripts
>     works as expected:
> 
>     <Location />
>           DirectoryIndex index.pl <http://index.pl> index.html
>           AddHandler cgi-script .pl
>           Options +Indexes +FollowSymLinks +ExecCGI
>           Require all granted
>     </Location>
> 
>     If I change this to use mod_perl, all output from scripts run in web
>     pages ends up in the apache log:
> 
>     <Location />
>           DirectoryIndex index.pl <http://index.pl> index.html
>           AddHandler perl-script .pl
>           Options +Indexes +FollowSymLinks +ExecCGI
>           Require all granted
>     </Location>
> 
>     The perl code I'm using in the web page is as follows:
>     my $cmd = "/bin/stdbuf";
>     my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
> 
>     print '<pre class="alert">';
>     my $pid = open3(0, \*READER, 0, $cmd, @args);
>     while ( my $output = <READER> ) {
>           print $output;
>     }
>     print "Speed test complete.</pre>";
>     waitpid $pid,0;
> 
>     Does anyone have any clues as to why STDOUT would end up in the apache
>     log and not in the web page being served when using perl-script as the
>     handler?
> 
>     -- 
>     Steven Haigh
> 
>     📧 netwiz@crc.id.au <ma...@crc.id.au>
>     💻 https://crc.id.au <https://crc.id.au>
> 
> 

-- 
Steven Haigh

📧 netwiz@crc.id.au
💻 https://crc.id.au


Re: stdout from scripts goes to apache logs

Posted by Ian B <ib...@gmail.com>.
Not an expert here, so someone I'm sure will correct me if wrong!

Normally I'd expect an actual PerlHandler or similar included, eg  PerlHandler
ModPerl::Registry   or PerlHandler SomeLib::SomePAckage type thing...
(this would be as well as the Set/AddHandler line)

Kind regards,

On Mon, May 13, 2024 at 7:54 AM Steven Haigh via modperl <
modperl@perl.apache.org> wrote:

> Hi all,
>
> I'm playing around with mod_perl on apache on docker - and now I've
> finally got all the module issues sorted, I'm trying to figure out why
> when using mod_perl, the output of scripts ends up in the apache logs.
>
> The following configuration works, and the output of shelled scripts
> works as expected:
>
> <Location />
>      DirectoryIndex index.pl index.html
>      AddHandler cgi-script .pl
>      Options +Indexes +FollowSymLinks +ExecCGI
>      Require all granted
> </Location>
>
> If I change this to use mod_perl, all output from scripts run in web
> pages ends up in the apache log:
>
> <Location />
>      DirectoryIndex index.pl index.html
>      AddHandler perl-script .pl
>      Options +Indexes +FollowSymLinks +ExecCGI
>      Require all granted
> </Location>
>
> The perl code I'm using in the web page is as follows:
> my $cmd = "/bin/stdbuf";
> my @args = qw@ -o1 -e1 /usr/bin/speedtest-cli@;
>
> print '<pre class="alert">';
> my $pid = open3(0, \*READER, 0, $cmd, @args);
> while ( my $output = <READER> ) {
>      print $output;
> }
> print "Speed test complete.</pre>";
> waitpid $pid,0;
>
> Does anyone have any clues as to why STDOUT would end up in the apache
> log and not in the web page being served when using perl-script as the
> handler?
>
> --
> Steven Haigh
>
> 📧 netwiz@crc.id.au
> 💻 https://crc.id.au
>
>
>