Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I googled for this problem but there is no answer for it.

I want my PHP script to generate HTTP response in chunked( http://en.wikipedia.org/wiki/Chunked_transfer_encoding). How to do it?

Update: I figured it out. I have to specify Transfer-encoding header and flush it.

header("Transfer-encoding: chunked");
flush(); 

The flush is necessary. Otherwise, Content-Length header will be generated.

And, I have to make chunks by myself. With a helper function, it is not hard.

function dump_chunk($chunk)
{
    echo sprintf("%x
", strlen($chunk));
    echo $chunk;
    echo "
";
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
943 views
Welcome To Ask or Share your Answers For Others

1 Answer

A PHP response will always be chunked if you don't specify a content-length header, and a flush occurs. (which will happen automatically after x bytes, just don't know exactly how much).

This is a weird thing to care about. Is this some kind of academic/learning exercise or is there a real world problem you're trying to solve?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...