ismail has asked for the wisdom of the Perl Monks concerning the following question:

Oh Benevolent Monks,

I'm having a problem with my CGI scripts on a Linux box I never use. When I get an error in a Perl CGI script, it prints the error to STDOUT instead of STDERR. Thus, when I run a script that has a trivial error (Use of uninitialized value in concatenation ...), it is printed as the first line, thus generating a Premature End of Script Headers error in the Apache error_log.

Now, I know I can put a BEGIN {} block in to flush the STDOUT handle, or use CGI::Carp to the same effect, but on my own box, as well as most development boxes I've used, the CGI errors (specifically, the perl errors) are flushed to STDERR, and thus handled by Apache. A friend of mine seems to think it's a Perl setting, and I couldn't find anything about it scouring the Apache lists. Any thoughts?

Environment: Mandrake 8.1, most packages installed by RPM, Perl 5.6.1 installed by CPAN.

Thanks ever so much,
Ismail

Replies are listed 'Best First'.
Re: Perl CGI errors to apache/error_log
by Fastolfe (Vicar) on Mar 30, 2002 at 03:15 UTC
    CGI::Carp was designed specifically for this. I use a configuration identical to yours and have not had problems with this technique. Perl CGI errors invariably end up in the error logs as desired (or in the browser for those cases where I specify fatalsToBrowser).

    Is this just not working for you?

      Yeah, it's not working. Tailing the error_log will give "Premature End of Script Headers" errors but not, for instance, DBI errors, or specific perl errors. It's very odd -- I've never seen anything like this. It's like there is a 2>&1 somewhere in the mix. Everything was set up by ApacheToolbox, but I haven't been able to find this issue there, nor the apache lists, nor the perl lists. Thanks, Ismail
        Have you isolated it to Apache?
        What happens when you run the script from the command-line and redirect stderr to a file?

        Are you running mod_perl? If so, try it with straight mod_cgi and see if that works okay.