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

I am using CGI::Application::Plugin::Stream in one of the runmodes of a cgi app. And it sometimes behaves strange, especially under FCGI.

Now I came across this note in the ::Stream docs: "It's recommended that you increment $| (or set it to 1), which will autoflush the buffer as your application is streaming out the file."
The special vars docs say "$| means If set to nonzero, forces a flush after every write or print", but how do I use this in my cgi app?

Replies are listed 'Best First'.
Re: What does "increment $| or set it to 1" mean for my CGI app?
by Anonymous Monk on Feb 04, 2012 at 14:28 UTC

    Why doesn't ::Stream set it after it has finished printing stuff to STDOUT automagically?

    Its none of its business ?:)

    I really don't know, this Bug #37038 for CGI-Application-Plugin-Stream: PATCH: improved auto-buffering and error handling. indicated it should have been done in 2008, go figure

    Shall I do ... in my runmode?

    You may :) You may also write that as

    { local $|=1; ... return; }

    Or does it mean I should switch the buffer mode in general for the whole app by stating $| = 1; in the setup() stage of CGI::App??

    It may. You could even

    { local $|=1; my $app = MyCGIAppSubclass->new; $app->run; }
Re: What does "increment $| or set it to 1" mean for my CGI app?
by Xiong (Hermit) on Feb 05, 2012 at 04:20 UTC

    my $prev_fh = select $outfh; local $| = 1; # autoflush select $prev_fh;
    I'm not the guy you kill, I'm the guy you buy. —Michael Clayton