How to measure the network bandwidth used between the client and server?

I have a client that receives a JSON response from the server. I want to calculate how many requests / replies my allocated transfer amount from a web host will consume (for example, 100 GB per month).

How to measure / calculate this?

I assume that I only need to measure once, because msgs have a consistent length and format.

I have control over the client / server / network. Everyone can be uniquely dedicated to this task. The client is an IOS application, and the server is the PHP REST web service (on Windows). Like on my local network.

I don't know anything about this and have so far gotten the JSON size using strlen() . Is it even a direction in the right direction?

+6
source share
3 answers

I would recommend using Charles Proxy . This is an invaluable tool for debugging all types of information exchanged via HTTP. You can use it to track all HTTP / s messages from and to your iPhone / iPod / iPad, as well as to the simulator.

Unfortunately, it does not work too well with most Android devices, as they do not support setting up a system-wide HTTP proxy. For these cases and non-HTTP communications, I would recommend using WireShark .

In some rare cases, for reasons that are still unclear, Charles rarely fails on iOS devices for HTTP connections — a typical case would be GoogleAnalytics. For those again, I would recommend WireShark.

+2
source

The JSON string length only gives the size of the payload field in the transmitted network packets. This data field can be encapsulated in an HTTP packet, and the HTTP packet must be placed in the IP packet before transmission. Each of these packets has header fields that contribute to the total transmission length.

So, for an accurate estimate, you must first find the real length of the response packet using Wireshark or an equivalent tool. If this is the only request type for your application, you can divide your bandwidth by the response size of your server application to get the maximum number of requests to reach the limit. However, this is usually not the case if you have a web application with several web pages available for clients, since any access (viewing) will transfer data from the server to the client.

+2
source

Your Apache logs will indicate the number of bytes of each request, but if you want a completely PHP solution, add this to the top of your scripts:

 <?php function log_input() { # get raw post data $length = strlen(file_get_contents('php://input')); if (function_exists('apache_request_headers')) { # quick, but not accurate $length += strlen(serialize(apache_request_headers())); } else { # add fudge for HTTP/1.1 etc $length += strlen($_SERVER['QUERY_STRING']) + 14; foreach ($_SERVER as $k => $v) { if (preg_match('/^HTTP/i', $k)) { $length += strlen($k) + strlen($v); } } } $s = sprintf("%s\t%s\n", date('c'), $length); file_put_contents('/tmp/input.log', $s, FILE_APPEND); } function log_output() { $s = sprintf("%s\t%s\n", date('c'), ob_get_length()); file_put_contents('/tmp/output.log', $s, FILE_APPEND); } log_input(); register_shutdown_function('log_output'); ob_start(); ?> <html> .... 
+1
source

Source: https://habr.com/ru/post/923793/


All Articles