'How to know how many bytes sent to client?

Is it possible to know how many bytes sent to the client browser using php? My pages are created dynamically, so the size isn't fixed.

php


Solution 1:[1]

Using php's output buffering

// start output buffering
ob_start();

// create your page

// once the page is ready, measure the size of the output buffer
$length = ob_get_length();
// and emit the page, stop buffering and flush the buffer
ob_get_flush();

As usual with php, these functions are pretty well documented in the standard documentation, don't forget to read the user contributed notes.

Solution 2:[2]

You can see this in your webserver's access log file.

But you can also code some php to get an answer like this:

ob_start();

echo "your content"

$data = ob_get_contents();

$size = strlen($data);

see also: Measure string size in Bytes in php

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Community