in reply to When to use Autoflush

Fastolfe has some good comments, but I want to expand a bit. There are additional reasons it might be necessary to turn off buffering:

First, if you have a potentially slow connection, and it could take longer than your timeout to generate enough information to fill the buffer.

Second, if the information you send has a positional aspect (as in, the HTTP headers must precede the content). If the potential exists that an error message may go out before the full headers, you may disable buffering.

The disclaimer, of course, is that I'm not an expert here. :)

Replies are listed 'Best First'.
Re: Re: When to use Autoflush
by Fastolfe (Vicar) on Dec 06, 2000 at 05:50 UTC
    Second, if the information you send has a positional aspect (as in, the HTTP headers must precede the content). If the potential exists that an error message may go out before the full headers, you may disable buffering.

    This actually brings us to another caveat: Don't mix buffered and unbuffered output. If your script writes to STDOUT and STDERR, and both of these somehow find their way through the network connection, note that STDOUT is buffered by default but STDERR is not. This is why you'll occasionally see "errors" appear before the actual output. The output is being mixed and naturally buffered output will appear later.