How can I get errors with a Perl script running FCGI.pm to appear in the Apache error log?

The following is an example script:

#!/usr/bin/perl use FCGI; my $request = FCGI::Request(); while($request->Accept() >= 0) { die "test"; } 

I expect this to print a “test” in the Apache error log, according to the FCGI specification , but nothing happens instead. If I move the stamp outside and before the while loop, the message is printed in the error log.

For more information about Apache configuration, this line is used to configure the handler:

 Addhandler fcgid-script .fcgi 

I was told that suexec is used and acts like a wrapper fcgi.


Edit:

A partial solution is brought up by FCGI.pm itself :

No stamps and warnings are set by default. This means that if you do not use perl with sfio support, any warning or death message will not be displayed in the server’s log by default. It is recommended that you set yourself to die and warn handlers. FCGI.pm contains an example of the die and warn handlers.

As such, I tried this as follows:

 #!/usr/bin/perl use FCGI; use IO::Handle; my ( $stdin, $stdout, $stderr ) = ( IO::Handle->new, IO::Handle->new, IO::Handle->new ); my $request = FCGI::Request( $stdin, $stdout, $stderr ); my $err_handler = sub { print {$stderr} @_ }; while($request->Accept() >= 0) { $SIG{__WARN__} = $SIG{__DIE__} = $err_handler; warn "test1"; die "test2"; } 

test2 appears in my error log without any problems, however test1 does not work.

+4
source share
1 answer

I tried to reproduce your problem with the FastCGI client written in Perl, FCGI.pm gives the expected result. Perhaps the problem is with mod_fcgid.

 #!/usr/bin/perl use strict; use warnings; use IO::Socket qw[]; use Net::FastCGI::Constant qw[:type :role]; use Net::FastCGI::IO qw[read_record write_record write_stream]; use Net::FastCGI::Protocol qw[build_params dump_record build_begin_request_body]; use warnings FATAL => 'Net::FastCGI::IO'; use constant TRUE => !!1; my $socket = IO::Socket::INET->new(Proto => 'tcp', Listen => 5) or die qq/Could not create a listener socket: '$!'/; my $host = $socket->sockhost; my $port = $socket->sockport; defined(my $pid = fork()) or die qq/Could not fork(): '$!'/; if (!$pid) { close STDIN; open(STDIN, '+>&', $socket) or die qq/Could not dup socket to STDIN: '$!'/; require FCGI; my $r = FCGI::Request() or die qq/Could not create a FCGI request: '$!'./; while ($r->Accept >= 0) { print "Perl: $] OS: $^O FCGI: $FCGI::VERSION\n"; warn "test1"; die "test2"; } exit(0); } close $socket; $socket = IO::Socket::INET->new(Proto => 'tcp', PeerHost => $host, PeerPort => $port) or die qq/Could not connect to '$host:$port': ' $@ '/; write_record($socket, FCGI_BEGIN_REQUEST, 1, build_begin_request_body(FCGI_RESPONDER, 0)); write_stream($socket, FCGI_PARAMS, 1, build_params({}), TRUE); write_stream($socket, FCGI_STDIN, 1, '', TRUE); while () { my ($type, $request_id, $content) = read_record($socket) or exit; warn dump_record($type, $request_id, $content), "\n"; last if $type == FCGI_END_REQUEST; } 

Output

 {FCGI_STDERR, 1, "test1 at fcgi-die.pl line 35.\ntest2 at fcgi-die.pl line 36.\n"} {FCGI_STDERR, 1, ""} {FCGI_STDOUT, 1, "Perl: 5.014001 OS: darwin FCGI: 0.74\n"} {FCGI_STDOUT, 1, ""} {FCGI_END_REQUEST, 1, {0, FCGI_REQUEST_COMPLETE}} 
0
source

All Articles