1

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.

Anders
  • 8,307
  • 9
  • 56
  • 88

2 Answers2

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

Community
  • 1
  • 1
Michael
  • 1,247
  • 1
  • 8
  • 18