【发布时间】:2017-01-12 19:46:16
【问题描述】:
是否可以知道使用 php 发送到客户端浏览器的字节数?我的页面是动态创建的。所以大小不是固定的。
谢谢
【问题讨论】:
-
@LandelinDelcoucq 我不认为这个问题涵盖了 OP 的用例......
-
出于兴趣,为什么要知道大小?
是否可以知道使用 php 发送到客户端浏览器的字节数?我的页面是动态创建的。所以大小不是固定的。
谢谢
【问题讨论】:
您可以在您的网络服务器的访问日志文件中看到这一点。
但你也可以编写一些 php 代码来得到这样的答案:
ob_start();
echo "your content"
$data = ob_get_contents();
$size = strlen($data);
【讨论】:
使用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 一样,这些函数在标准文档中都有很好的记录,不要忘记阅读用户提供的注释。
【讨论】: