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}}
source share