[jifty-devel] $m->flush_buffer question

Thomas Sibley trs at bestpractical.com
Mon Jul 11 17:43:16 EDT 2011

On 07/07/2011 04:35 PM, Henry Baragar wrote:
> I'm trying to download 500MB of data (3M records) and would like to
> flush the output buffer every 1K records so that the browser (or web
> server) does not time out. With a plain Mason application calling
> $m->flush_buffer does the trick, but this does not seem to be working in
> Jifty 1.10518.
> Do I have to do something else in Jifty to get it to flush the output
> midstream?

Hmm, this is an interesting problem.  I believe what you have below used
to work with Jifty, but broke when we moved to PSGI/Plack as our
interface to web servers.

There is support for streaming responses, but it looks like from the
dispatcher only at this point.  There's some work that could be done
here, but try this basic example in your dispatcher:

on 'streamy' => stream {
    return sub {
        my $responder = shift;
        my $writer = $responder->(
            [200, ['Content-Type', 'text/plain']]
        for my $i (1..10) {
            $writer->write("line $i\n");
            sleep 1;

That may need some extra headers for various browsers, but I think it'll
just work even if it's not ideal.


More information about the jifty-devel mailing list