NYCPHP Meetup

NYPHP.org

[nycphp-talk] send header before end of script?

Chris Shiflett shiflett at php.net
Fri Oct 24 19:07:41 EDT 2003


--- David Mintz <dmintz at panix.com> wrote:
> I did buy Shiflett's book (wow, can't wait for the movie to come
> out!) and it seems you can do cool tricks at the protocol level
> with the "Transfer-Encoding: chunked" header, spitting out chunks
> as you go along (although I've yet to try it), but I wonder how one
> does it in "pure" PHP with the buffering functions.

I hope you enjoy the book. :-)

There is an example on page 173 that shows how to perform chunked transfers
with PHP, and you can try it out from this page (it's flush.phps):

http://shiflett.org/books/http-developers-handbook/code

The flush() function is a tough one to debug when it doesn't work. Basically,
anything that buffers output can potentially cause problems. This includes the
Web server and the browser (IE, notably) in addition to things like ob_start().

If you try my example from my Web site, and it doesn't work, it's definitely
your browser that is doing the buffering. There are some tricks to get around
this with IE, such as sending at least 256 bytes of whitespace before any other
output. My example doesn't include this trick.

If the example on my Web site does work, then your browser definitely handles
the chunked transfer correctly. If you use output buffering within PHP, you'll
have to flush that and then also flush() to send a new chunk.

Hope that helps.

Chris

=====
My Blog
     http://shiflett.org/
HTTP Developer's Handbook
     http://httphandbook.org/
RAMP Training Courses
     http://www.nyphp.org/ramp



More information about the talk mailing list