【问题标题】:How to know how many bytes sent to client?如何知道发送给客户端的字节数
【发布时间】:2017-01-12 19:46:16
【问题描述】:

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

【问题讨论】:

标签: php browser


【解决方案1】:

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

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

ob_start();

echo "your content"

$data = ob_get_contents();

$size = strlen($data);

另请参阅:Measure string size in Bytes in php

【讨论】:

    【解决方案2】:

    使用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 一样,这些函数在标准文档中都有很好的记录,不要忘记阅读用户提供的注释。

    【讨论】:

    • ob_get_length(),不错!
    猜你喜欢
    • 1970-01-01
    • 2013-04-27
    • 2022-01-20
    • 2016-03-29
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 2019-06-30
    相关资源
    最近更新 更多