Alex Rivera | Logout

"Transfer-Encoding: chunked" header in PHP

Asked 2011-01-26T20:39:28.577
9

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?

Edit
Report

1 Answer

-2

Use ob_flush(); before flush();

Sample code:

<?php
        header('Content-Encoding', 'chunked');
        header('Transfer-Encoding', 'chunked');
        header('Content-Type', 'text/html');
        header('Connection', 'keep-alive');

        ob_flush();
        flush();

        $p = "";  //padding
        for ($i=0; $i < 1024; $i++) { 
            $p .= " ";
        };
        echo $p;

        ob_flush();
        flush();

        for ($i = 0; $i < 10000; $i++) {
            echo "string";
            ob_flush();
            flush();
            sleep(2);
        }

?>
answered 2012-07-05T03:25:33.270

Your Answer