Trying to put it simply, the script runs from top to bottom with 2 exit points. If cache control is met by comparing last modifed date and etag then the script exits with a 304. Otherwise the HTML is built from a template and held in a scalar, so the length can be calculated, the headers are output followed by the body and then the script exits.
My expectation, based on how Apache serves files, is that if the browser sends Keep-Alive then the server responds with Keep-Alive, a timeout value and max objects value. If the next request is within the timeout value and the max objects has not been met then the request is served on the open connection, the timer is reset and the max object decremented by 1. If there is no further request within the timeout or the max objects is met then the connection is closed by the server. You can partially see this in the two header traces that I posted above.
What I'm trying to figure out is how do I replicate the normal Apache behavior for keep-alive. I mimic the headers exactly but Apache does not honour what has been sent. My assumption is that it's to do with the fact that it's NPH. Normally Apache would append these headers. What I need to be able to do is access the Apache timeout value and the max objects value so I can set those appropriately and inform Apache to decrement the max objects value and have Apache not tear down the connection.
That's my understanding and I hope that makes sense.