小型站点使用日志文件轮换为每个月生成单独的Web服务器日志文件。 我需要编写一个PHP脚本来检查日志文件中的数据并生成一个 单个简短摘要HTML页面,包含所有月份的使用情况统计信息。我有2个月的两个示例Web服务器日志文件。统计摘要应包含:
到目前为止,下面的代码打开了目录文件,但是我很难生成统计信息,有什么建议吗?
示例日志文件
118.83.4.180 -- [2007-05-01 00:43:38] "GET docs/php_class_syntax HTTP/1.0" 200 10035 "Mozilla/4.0"
20.60.92.212 -- [2007-05-01 01:27:16] "GET docs/regex_crib_sheet HTTP/1.0" 200 12901 "Mozilla/4.0"
133.226.169.34 -- [2007-05-01 02:10:55] "GET not/available HTTP/1.0" 404 0 "Mozilla/4.0"
22.247.135.0 -- [2007-05-01 02:54:33] "GET reference/php_syntax HTTP/1.0" 200 8467 "Mozilla/4.0"
249.33.56.182 -- [2007-05-01 03:38:11] "GET index.php HTTP/1.0" 200 3836 "MSIE 7.0"
124.211.253.106 -- [2007-05-01 04:21:49] "GET articles/dynamic_images_with_php HTTP/1.0" 200 13037 "MSIE 7.0"
PHP代码
<?php
// Open log file
$directory = 'files';
if($handle = opendir($directory.'/')) {
echo 'These files contains \' '.$directory.'\':<br/>';
while(false !== ($file = readdir($handle))) {
if($file!='.'&&$file!= '..') {
echo '<a href ="'.$directory.'/'.$file.'">'.$file.'<br/>';
}
}
}
?>