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.
Asked
Active
Viewed 211 times
1
-
Possibly duplicated answer : http://stackoverflow.com/questions/1507985/php-determine-how-many-bytes-sent-over-http – Landelin Delcoucq Sep 05 '16 at 12:28
-
@LandelinDelcoucq I don't think that question covers OP's use case... – fvu Sep 05 '16 at 12:29
-
Out of interest, why do you want to know the size? – RiggsFolly Sep 05 '16 at 12:34
2 Answers
3
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.

fvu
- 32,488
- 6
- 61
- 79
1
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