你的Apache日志都会有每个请求的字节数,但假设你想要一个完全PHP的解决方案,将它添加到你的脚本的开头:
<?php
function log_input() {
# get raw post data
$length = strlen(file_get_contents('php://input'));
if (function_exists('apache_request_headers')) {
# quick, but not accurate
$length += strlen(serialize(apache_request_headers()));
} else {
# add fudge for HTTP/1.1 etc
$length += strlen($_SERVER['QUERY_STRING']) + 14;
foreach ($_SERVER as $k => $v) {
if (preg_match('/^HTTP/i', $k)) {
$length += strlen($k) + strlen($v);
}
}
}
$s = sprintf("%s\t%s\n", date('c'), $length);
file_put_contents('/tmp/input.log', $s, FILE_APPEND);
}
function log_output() {
$s = sprintf("%s\t%s\n", date('c'), ob_get_length());
file_put_contents('/tmp/output.log', $s, FILE_APPEND);
}
log_input();
register_shutdown_function('log_output');
ob_start();
?>
<html> ....
Firebug Net选项卡可以为您提供数据包大小。 –
阅读这些答案我意识到我不清楚我的问题。没有涉及HTML。我在IOS设备上有一个(objective-c)应用程序,用于查询PHP Restful Web服务。我会更新这个问题。但我认为我可以为此调整答案。我现在就试试。 – Polly
使用Charles代理来获取该信息 – Till