PHP计算当前请求的大小(字节)

Have a question about monitoring data transfer.

Our situation would be something similar to

Apache Server  <-----> Mobile Device

We need to do 2 things

  1. Calculate the size of the page/raw data getting sent to the mobile device.
  2. Calculate the size of the request/raw data coming from the device.

So in our database we'd be able to store like

Device ID | Uploaded | Downloaded

The logic for the saving etc is fine, we just need to know how we'd calculate the size of the requests.

I believe when the device sends the server information, we can use PHP to read $_SERVER['CONTENT_LENGTH']; to see how big that piece of data is. However not sure how we'd do this the other way around.

It depends how the data is encoded when it's outputed. If you are using the json_format you can use strlen function.

Example

echo $data; where $data = json_encode(array('what' => 'you, 'send'));

and a simple

$len = strlen($data); will show you.

If it's the right way I understood the question.