如何知道发送到客户端的字节数

时间:2016-09-05 12:24:57

标签: php browser

是否可以知道使用php发送到客户端浏览器的字节数?我的页面是动态创建的。所以尺寸不固定。
谢谢

2 个答案:

答案 0 :(得分:3)

使用php的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();

与php一样,这些功能在标准文档中都有很好的记录,不要忘记阅读用户提供的注释。

答案 1 :(得分:1)

您可以在网络服务器的访问日志文件中看到这一点。

但你也可以编写一些php来得到这样的答案:

ob_start();

echo "your content"

$data = ob_get_contents();

$size = strlen($data);

另见:Measure string size in Bytes in php