The chunks are sent in just one HTTP POST. The connection persists. If you capture de traffic you will see a persistent TCP connection, with no differences between a normal request.
But I'm using chunked encoding, supported in HTTP which is used to read properly the body as the chunks come. The body is splited in chunks and the receiver can read the body progessively, instroducing less delay time than the classic way which waits the close of the HTTP connection to start to read the body.
When the body is fully received, the destination answers with just one 200 OK.
In my example, we have a client which sends "hi", waits 2 seconds and then sends "there". The HTTP connection is just one, and is closed when the second chunk is received. The problem is that the PHP script in sever side, starts when the last chunk "there" is received. In my PHP script, I have:
Code: Select all
header('Content-type: application/json; charset=utf-8');
$file_reader = fopen('php://input', "r");
$body = fgets($file_reader,20);
echo $body. '<br />';
echo "bija". '<br />';
So, because the script instance starts when the whole body is received in the first echo+flush() in the body is sent "hithere". Then, we have a sleep(2) which waits 2 seconds, and then the server sends "bija" as a second chunk, closing the HTTP connection a little more than 4 secs from the begining (2 secs sleep in client + 2 secs sleep in server + little processing and traffic). The chunked header is automatically generated.
As you can see, I'm sending a chunked request and a chunked response. There aren't issue about protocol/communication. The problem is that the PHP script is executed when the full request is received. I can send "hithere" and "bija" as separated chunks, or "hi" and "there" too. But the problem is not about "what", the problem is about "when". I cannot start sending my answer when the first chunk arrives, I must wait to the POST request is received completely. But I don't want to send the response in chunks, my need is easier, I just want to start processing the body, chunk by chunk for do another action.
For example: I receive one chunk, and then I open another chunked HTTP connection, stablishing a continuous flux end to end. If I retransmit the same message I reveice, I'm doing an end to end streaming flux with my server in the middle.
I'm attaching some of my Wireshark captures as images, showing that.