You can use the chunked transfer encoding to write sequentially to the client. Browsers (usually) parse and display the sent data immediately after the first chunk is read.
Update: mod_perl example
package My::Stream;
use strict;
use warnings;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw( OK );
sub handler :method {
my $invocant = shift;
my $request_record = shift;
$request_record->content_type( 'text/html' );
for ( 1 .. 10 ) {
$request_record->print( "<p>$_</p>" );
$request_record->rflush;
sleep 1;
}
return Apache2::Const::OK;
}
1;