in reply to how to implement "tail -f" using CGI

put $|=1; at the top of your script. This will unbuffer output.

in case that's hard to read, it's "$|=1;"

Replies are listed 'Best First'.
Re: Re: how to implement
by mr.nick (Chaplain) on May 17, 2001 at 01:46 UTC
    That doesn't seem to quite work. I wrote the follow test:
    #!/usr/bin/perl $|=1; print "Content-type: text/html\n\n"; for (1..20) { print "$_<br>\n"; sleep 2; }
    and the browser still waits until all 20 numbers are outputted before returning the page.

    This is under IE 5.0, Perl 5.005 and Apache 1.3.19.

    Update: If I increase the range to something higher, I find that around 40 or so, it's starts to output. Apache itself must be doing some buffering ...

      The guilty party here is IE, not apache. I just compared IE6 to N4.76, both on win2000. IE won't display anything before it has read about 230 bytes. If you then reload the page, there's no buffering.

      quick fix:

      print "<!-- hey IE, display this page already -->\n" x 5;
      --
      Brigitte    'I never met a chocolate I didnt like'    Jellinek
      http://www.horus.com/~bjelli/         http://perlwelt.horus.at

      Sorry for being *nix-centric. I only have done perl coding on linux/unix. I don't know how unbuffering behaves on a windows machine. This works perfectly on my linux boxes. Sorry!

        Who said I was doing this on Windows? Ah! The "IE 5.0". Well, my browser is running on Win2k, but everything else is under Linux.

        Btw, it seems that Apache (at least my copy) buffers in 512 byte blocks; regardless of what the CGI itself is doing.