Advanced PHP |
 |
2025-02-24 |
 |
 |

8 |
 |
 |
When a keep-alive request is granted the established socket is kept open
after each keep-alive response. Note that a keep-alive response is only
possible when the response includes a content-length header.
request 1 |
request 2 |
request 3 |
request 4 |
20 bytes |
120 bytes |
60 bytes |
?? bytes |
|
You cannot rely on the keep-alive feature for any sort of application-level
session state maintenance.
Using Output Buffering to get content-length
<?php
ob_start();
echo "Your Data";
$l = ob_get_length();
Header("Content-length: $l");
ob_end_flush();
?>
You will have to weigh the trade-off between the extra cpu and memory that
output buffering takes against the increased effciency of being able to use keep-alive
connections for your dynamic pages.