I want to calculate the size in bytes of the http response headers and data in PHP. Any help would be appreciated
4
-
3Whose response headers, in what context?Pekka– Pekka2010-10-27 09:35:43 +00:00Commented Oct 27, 2010 at 9:35
-
Are you serving the response headers, or expecting a response from another server that your PHP application contacts, say using cURL?BoltClock– BoltClock2010-10-27 09:42:21 +00:00Commented Oct 27, 2010 at 9:42
-
the requirement is to log http request and response size.RJ.– RJ.2010-10-27 09:53:42 +00:00Commented Oct 27, 2010 at 9:53
-
i managed to find the http request size using getallheaders(), now i want to calculate the size of the response data as well as size of http headers sent during responseRJ.– RJ.2010-10-27 09:55:07 +00:00Commented Oct 27, 2010 at 9:55
Add a comment
|
1 Answer
You can't measure the size of the response headers from your PHP code because the webserver may change them before serving them up. Only the webserver can measure this - and you don't say what webserver you are using. With Apache, install mod_logio and start recording %I, %O and %B
4 Comments
RJ.
getheaders() would give you the complete header response, but it would add to additional call
symcbean
@RJ: only after the headers have been flushed (and only if the encoding is not chunked)
RJ.
Could you explain "encoding is not chunked", i didn't get it
symcbean
@RJ: if the encoding is chunked, then the webserver will send a set of headers, then the first chunk of the body, then more content which is effectively a header before the next chaunk - your PHP code doesn't know where the webserver has split the body