How to make PHP generate Chunked response

后端 未结 9 2071
渐次进展
渐次进展 2020-11-28 06:32

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_en

9条回答
  •  孤独总比滥情好
    2020-11-28 07:23

    If the size is big enough, Apache do it for you. If you work with ob_gzhandler, I think it makes no sense. Better you let the buffer out as fast as possible. If PHP really does not send automatically the content-length header or the content-length is from the uncompressed content:

    ob_start();
    ob_start("ob_gzhandler");
    ...
    ob_end_flush();  
    header('Content-Length: '.ob_get_length()); 
    ob_end_flush();
    

    You could reduce buffer size with apache's mod_buffer (may be with PHP's ini_set).

    PS: If the size is big enough and the content-length is unknown, the content will be send in chunks as a makeshift.

提交回复
热议问题