i want to add Transfer-Encoding: chunked
header to the file that i'm outputing (its just generated plain text), but when i add:
header("Transfer-Encoding: chunked");
flush();
the browser doesn't want to open the file.
The webpage at ... might be temporarily down or it may have moved permanently to a new web address.
what i need to do for it to work?
Use
ob_flush();
beforeflush();
Sample code:
For me when I was trying something with "Transfer-Encoding: chunked" I had to use this code to make it work:
This code will still have the "Transfer-Encoding: chunked" header.
It automatically sets the Transfer-Encoding heading when you use flush but when it set it manually it fails, so to prevent any problems try to remove it. Also make sure that you remove the heading on the line before you do your first flush to prevent errors.
You need to send the
Content-Length
with every chunk you send. Look at Wikipedia for a first impression, how a chunked encoding looks like. Its not that trivial and in many cases its oversized.Update: First you send the headers, because they must always send before any content (also with chunked encoding). Then you send (for every chunk) the size (in hexadecimal) followed by the content. Remember
flush()
after every chunk. At last you must send a zero-size chunk to make sure, that the connection get closed properly.Its not tested, but something like this
As previous members said you have to follow chunked transfer encoding format.
In next example i will show how you can use one user function to follow format rules:
Notes: