How to generate a chunked response using Trailer in Apache / PHP?

I know that I can generate a chunked response in PHP by simply typing sleep()in the output.

But is it possible to also generate a Trailer HTTP section in PHP? If not, is it even possible in Apache 2.2?

I need this for testing purposes.

+5
source share
1 answer

PHP will send a default response if the headers are sent and the header is Content-Lengthnot specified. If you are familiar with the HTTP specification, this is the only logical thing to do, as the client on the other end needs to know when the HTTP message you send ends so that it can stop reading.

, ...

  • flush()
  • chunked HTTP-

, - . , . , Content-Length, PHP .

header("Transfer-encoding: chunked");
header("Trailer: X-My-Trailer-Header");
flush();

echo dechex(strlen($myChunk)) . "\r\n";
echo $myChunk;
echo "\r\n";
flush();

echo "0\r\n";
flush();

echo "X-My-Trailer-Header: some-value\r\n";
flush();
+2

All Articles