Re: stdout from scripts goes to apache logs
"Steven Haigh via modperl" <[email protected]> Tue, 14 May 2024 13:37:47 +1000
| Newsgroups | gmane.comp.apache.mod-perl |
|---|---|
| Message-ID | <[email protected]> |
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
> <[email protected] <mailto:[email protected]>> 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
> > <[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>>
> 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
> > > <[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>
> > <mailto:[email protected]
> <mailto:[email protected]> <mailto:[email protected]
> <mailto:[email protected]>>>>
> > 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
> > >
> > > 📧 [email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>
> > <mailto:[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>>
> > > 💻 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
> >
> > 📧 [email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>
> > 💻 https://crc.id.au <https://crc.id.au> <https://crc.id.au
> <https://crc.id.au>>
> >
>
> --
> Steven Haigh
>
> 📧 [email protected] <mailto:[email protected]>
> 💻 https://crc.id.au <https://crc.id.au>
>
--
Steven Haigh
📧 [email protected]
💻 https://crc.id.au