How to stream HTML output?

B

burak

Hey all...

I'm pretty sure I recall there being a way to control HTML output so
that stuff prints to the screen as you're waiting, instead of it being
buffered and come out when the script dies.

I have a pretty intense (and somewhat slow) script, and I would like
the progress of the script to display on the page as the script is
finishing up. Any ideas on how to do this?

Thanks in advance,
Burak
 
I

it_says_BALLS_on_your_forehead

Hey all...

I'm pretty sure I recall there being a way to control HTML output so
that stuff prints to the screen as you're waiting, instead of it being
buffered and come out when the script dies.

I have a pretty intense (and somewhat slow) script, and I would like
the progress of the script to display on the page as the script is
finishing up. Any ideas on how to do this?
I believe you must flush the buffer.
$| = 1;
# do whatever it is you need to do...
 
X

xhoster

Hey all...

I'm pretty sure I recall there being a way to control HTML output so
that stuff prints to the screen as you're waiting, instead of it being
buffered and come out when the script dies.

I have a pretty intense (and somewhat slow) script, and I would like
the progress of the script to display on the page as the script is
finishing up. Any ideas on how to do this?

Unbuffer your output. I do it not so much to see the output as it is
generated, but to prevent the connection from timing-out due to idleness.

$|=1;


Recently I had to prevent a CGI from timing out. It was calling a
long-running canned procedure which didn't report progress and didn't have
hooks to add progress reporting. This seems to work well for that:

{
local $SIG{ALRM}= sub { print ".\n"; alarm 10 };
alarm 10;
$object->long_running_thing();
alarm 0;
};

Thanks in advance,
Burak

Xho
 
A

Alan J. Flavell

(e-mail address removed) wrote: [...]
I have a pretty intense (and somewhat slow) script, and I would like
the progress of the script to display on the page as the script is
finishing up. Any ideas on how to do this?

Unbuffer your output.
OK...

I do it not so much to see the output as it is generated, but to
prevent the connection from timing-out due to idleness.

OK; but, over and above that, the questioner should make sure that
the emitted HTML really will be incrementally displayed by browsers.

There are some techniques which will cause the browser to save up the
output, waiting for something to happen before displaying it. E.g if
it's the content of an automatically-sized table - which, rather
obviously, can't be formatted and displayed until its content is
complete.

None of this is really Perl-specific, other than the recipes you gave.
I'm only mentioning it because unbuffering, on its own, might not
achieve the desired effect, due to other factors.

As Jim Gibson has pointed out, in some cases it might be preferable to
proceed the way Randal showed in col39. The choice between
incremental display on the one hand, and meta refresh on the other,
probably depends a lot on circumstances, and on how long the process
is likely to take.

cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top