【发布时间】:2015-11-09 19:25:14
【问题描述】:
您好,我正在尝试计算失败请求的百分比。 假设只有 200 和 404 错误代码,
到目前为止,我计划提取 IP 地址和错误代码并将它们放入一个数组中。 有没有比我采取的方法更好的方法来解决它
Sample access log content:
<pre>
192.168.2.20 - - [28/Jul/2006:10:27:10 -0300] "GET /try/ HTTP/1.0" 200 3395
127.0.0.1 - - [28/Jul/2006:10:22:04 -0300] "GET / HTTP/1.0" 200 2216
127.0.0.1 - - [28/Jul/2006:10:27:32 -0300] "GET /hidden/ HTTP/1.0" 404 7218
</pre>
and trying to output array as below
一个例子: 大批( "127.0.0.1" => 0.5, “192.168.2.20” => 0, )
function analyzeAccessLog($fileName)
{
//$fh = fopen($fileName,'r')
$people = file_get_contents($fileName);
if (preg_match('/\200|404?\w/',$people,$matches)) {
{
$int1=$matches[0];
print "$int1 \n";
}
}
}
analyzeAccessLog('log.txt');
【问题讨论】:
标签: php text-extraction