我被要求查看的一个网站流量很大。他们出于性能原因禁用了 access_log(不过看起来还不错),我想知道他们每分钟/每小时/等等有多少次点击。
如果不启用 access_log,我如何检查 Apache 服务器每分钟/每小时/每天的点击量?也许可以在主页上写一行代码进行估算?
答案1
您可以尝试启用mod_status它将为你提供这些信息以及更多信息,例如
Current Time: Wednesday, 16-Nov-2011 21:52:01 GMT
Restart Time: Wednesday, 16-Nov-2011 21:51:50 GMT
Parent Server Generation: 0
Server uptime: 10 seconds
Total accesses: 0 - Total Traffic: 0 kB
CPU Usage: u0 s0 cu0 cs0
0 requests/sec - 0 B/second -
1 requests currently being processed, 5 idle workers
W_____..........................................................
................................................................
................................................................
................................................................
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
0-0 4957 0/0/0 W 0.00 5 1369611147 0.0 0.00 0.00 192.168.1.73 host.lan GET /server-status HTTP/1.1
答案2
谷歌分析做得很好。
答案3
mod_status 是否启用?http://www.apache.org/server-status是一个示例输出,它有自启动以来的请求数和总计。
答案4
<?php
/*
In progress by HaZe as of 11-16-11
It gets the IP from the user, even behind a PHP proxy (VPNs are still hidden).
*/
if (getenv("HTTP_X_FORWARDED_FOR")) {
$ipaddress = getenv("HTTP_X_FORWARDED_FOR");
} else {
$ipaddress = getenv("REMOTE_ADDR");
}
$localdate = date("l j F Y g:ia", time() - date("Z"));
$useragent = $_SERVER['HTTP_USER_AGENT'];
$referer = $_SERVER['HTTP_REFERER'];
$page = $_SERVER['REQUEST_URI'];
$useragent = strip_tags($useragent);
$varlog = fopen("access-log-php.html", "a");
// Write data
fwrite($varlog, $ipaddress);
fwrite($varlog, "<br>");
fwrite($varlog, $localdate);
fwrite($varlog, "<br>");
fwrite($varlog, $page);
fwrite($varlog, "<br>");
fwrite($varlog, $useragent);
fwrite($varlog, "<br>");
fwrite($varlog, $referer);
fwrite($varlog, "<br><br>");
// Close file
fclose($varlog);
?>
您可以尝试一下,如果它是 PHP,只需将其添加到索引页,或者更好的是,将其作为 PHP 函数弹出到“Header.html”文件中。
每次加载时,它都会为您提供用户的 IP、引荐来源、用户代理和查看的页面。
粗略地说,将其保存在需要保存的地方,保存一小时,然后将其生成的文件 (access-log-php.html) 剪切并粘贴到不会被编辑的地方。您可以查看内部并计算命中次数。
或者,设置一个 PHP SQL 函数,使其以一为增量,并存储到数据库的表中,持续一小时。
但 PHP 才是最佳选择。