0

I want to calculate the size in bytes of the http response headers and data in PHP. Any help would be appreciated

4
  • 3
    Whose response headers, in what context? Commented 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? Commented Oct 27, 2010 at 9:42
  • the requirement is to log http request and response size. Commented 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 response Commented Oct 27, 2010 at 9:55

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

getheaders() would give you the complete header response, but it would add to additional call
@RJ: only after the headers have been flushed (and only if the encoding is not chunked)
Could you explain "encoding is not chunked", i didn't get it
@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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.