parlays
asked on
Is using Transfer Encoding: Chunked the best way to deliver HTML in pieces?
Hello everybody!
I've been looking at the headers of a few websites that I notice deliver their content in pieces. At first I thought they were using the PHP flush() funciton but realized this is not possible because they all deliver they content with GZip encoding. Then I noticed they have a header of "Transfer Encoding: Chunked" on sites that for instance display their header image and then as the database query starts to complete they start to display the content on the bottom.
How do I use Chunked transfer encoding using PHP? Is this the best way to output parts of an HTML page while there is still database queries going on? Thanks!!
I've been looking at the headers of a few websites that I notice deliver their content in pieces. At first I thought they were using the PHP flush() funciton but realized this is not possible because they all deliver they content with GZip encoding. Then I noticed they have a header of "Transfer Encoding: Chunked" on sites that for instance display their header image and then as the database query starts to complete they start to display the content on the bottom.
How do I use Chunked transfer encoding using PHP? Is this the best way to output parts of an HTML page while there is still database queries going on? Thanks!!
Chunked encoding happens, if the content-length is unknown. PHP delivers the content in pieces to apache httpd (php's standard output buffer size is 4096 bytes). If apache does not receive an end of stream marker by php yet, chunked encoding will take place. But if Apache receives an end of stream marker and nothing has been send out yet, the content-length is known, therefore there's no need for chunked encoding in that case.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
How do I use transfer encoding: chunked, what do I tell PHP to do?
Chunked is usually used for single large items that can be broken up - it's what download accelerators live on - and is commonly used with PDF as well (it can do things like deliver one page out of a big file).