0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
owenmelbz
  • 6,180
  • 16
  • 63
  • 113
  • do you mean the http request? or do you mean the request of the initial page as it is loading? – Liam Sorsby Oct 23 '13 at 11:21
  • You could probably use output buffering to calculate the script output size. Not sure what you could do about the response headers though – John V. Oct 23 '13 at 11:21
  • Btw., the data your server responds with might not actually be what the mobile device actually _receives_ … since many ISPs apply additional compression and data reduction when they send data over mobile connections … – CBroe Oct 23 '13 at 11:47
  • @LiamSorsby Sorry not entirely clear what you mean by "the initial page" – owenmelbz Oct 23 '13 at 12:35
  • @CBroe thanks for the information, will keep that in mind! The idea of monitoring is just to make sure the device doesn't go over its data-allowance. So if its compressed than that's only a good thing. – owenmelbz Oct 23 '13 at 12:36
  • @JohnV. thanks for the tip of output buffering, will give that a look! – owenmelbz Oct 23 '13 at 12:36

1 Answers1

0

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.