http://www.perlmonks.org?node_id=949066

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

Dear monks,

I have been getting sporadic errors in my modperl2, freebsd linux environment when a system command is executed. When it fails, which is roughly 25% of the time, the user gets a 500 error and there is a error log message of the form

"Fri Jan 20 16:31:44 2012 error client <IP> (null): flush can't be called before the response phase at /usr/local/apache/lib/perl/<module name> <line> <referer>".

From the <module name> and <line> values I can see these always correspond to system commands.

In the perldoc for system I found the below paragraph: "Beginning with v5.6.0, Perl will attempt to flush all files opened for output before any operation that may do a fork, but this may not be supported on some platforms (see perlport). To be safe, you may need to set $| ($AUTOFLUSH in English) or call the autoflush() method of IO::Handle on any open handles."

So I tried adding

local $| = 0;
before every system command but to no avail.

So it appears somehow the modperl http buffer is being flushed when system is called but I can't figure out why or what to do about it.

Any wisdom would be greatly appreciated!