<jo************@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I'm trying to figure out how to enable chunked encoding with php over
apache2 for a particular page. My php/apache combination definitely
supports chunked encoding, because a page which calls only phpinfo()
uses it. On the other hand, pages without phpinfo() don't get sent with
chunked encoding (content-length is used instead). Does anyone know
how to specifically enable chunked encoding for a given page?
Thanks,
Jon
Chunking doesn't happen if a content-length header is present. From the
source code:
if ((r->connection->keepalive != AP_CONN_CLOSE)
&& ((r->status == HTTP_NOT_MODIFIED)
|| (r->status == HTTP_NO_CONTENT)
|| r->header_only
|| apr_table_get(r->headers_out, "Content-Length")
|| ap_find_last_token(r->pool,
apr_table_get(r->headers_out,
"Transfer-Encoding"),
"chunked")
|| ((r->proto_num >= HTTP_VERSION(1,1))
&& (r->chunked = 1))) /* THIS CODE IS CORRECT, see above. */
The variable chunked would not get set if any of the previous conditions are
true. One of them being the presencce of a content-length header. Another,
which might make you scratch your head, is the presence of
"Thansfer-encoding: chunked".
The Apache 2 output filter will automatically add a content-length header if
it sees an end-of-stream marker AND nothing has been sent yet. From the
source code:
if (ctx->data_sent == 0 && eos) {
ap_set_content_length(r, r->bytes_sent);
}
If PHP passes any data down to Apache before it sends EOS, then chunking
happens. PHP uses a output buffer of 4096 bytes by default. Any page smaller
than that will not get chunked.