【问题标题】:PHP Traffic accountingPHP流量记账
【发布时间】:2013-11-27 14:12:26
【问题描述】:

我们正在使用 NGINX / apache 的访问日志计算客户的流量使用情况。 现在我想到了一个大问题。

如果我这样做会怎样:

<?php
    file_get_contents( "http://www.speedtest.qsc.de/1GB.qsc" );
?>

调用本身将是一个只有几个字节/千字节的简单 GET,但假设我们有足够的 memory_limit 和 max_execution_time,脚本将下载一个 1GB 的文件。 这根本不会被记录,对吧?

有没有办法像我上面提到的那样跟踪?

提前致谢

【问题讨论】:

    标签: php traffic-measurement


    【解决方案1】:

    对于 apache,默认日志是

    LogFormat "%h %l %u %t \"%r\" %>s %b"
    

    %b 代表Size of response in bytes, excluding HTTP headers. In CLF format, i.e. a '-' rather than a 0 when no bytes are sent

    你可能会使用它

    http://httpd.apache.org/docs/2.2/mod/mod_log_config.html

    对于 nginx,它也是默认的

    log_format compression '$remote_addr - $remote_user [$time_local] '
                           '"$request" $status $bytes_sent '
                           '"$http_referer" "$http_user_agent" "$gzip_ratio"';
    

    http://nginx.org/en/docs/http/ngx_http_log_module.html

    【讨论】:

    • 如果下载的文件没有显示并简单地丢弃,则不会计算 php 下载调用会产生的流量。响应为 0 字节(无输出)
    • 遗憾的是,我们无法更改客户代码中的任何内容,因此我们无法向源代码本身添加任何特殊的日志记录命令。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 2019-04-10
    • 1970-01-01
    相关资源
    最近更新 更多