使用方式复制到一个空的php文件即可。设置好日志目录就可以查看到数据。
<?php /** * 爱资料php日志分析工具v11 * by jack(chenran) * time 2016-2-15 * update 2016-3-5 * http://www.apizl.com */ error_reporting(0); header("Content-type: text/html; charset=utf-8"); $path = "D:\web\me-web\log\W3SVC28\\"; //日志地址 $file_list = scandir($path); $file_list = array_reverse($file_list); $count = count($file_list); $log_name = isset($_GET["log"]) ? $_GET["log"] : ""; if (empty($log_name)) { $path_ = $path . $file_list[0]; } else { $path_ = $path . $log_name; } $log = file_get_contents($path_); /** * 得到每行详细详细 * @param type $log * @param type $spider * @return type */ function httpinfo_w3c($log, $spider) { $arrlist = array(); preg_match_all('/(20' . date("y") . '.*' . $spider . '.*)/', $log, $matches); // for ($i = 0; $i < count($matches[0]); $i++) { $arr = explode(" ", $matches[0][$i]); $arr[4] = "http://" . $_SERVER["HTTP_HOST"] . $arr[4]; $arrlist[$i] = $arr; } return $arrlist; } /** * 返回总数 * @param type $log * @param type $spider * @return type */ function spider_count($log, $spider) { preg_match_all('/' . $spider . '/', $log, $matches); //谷歌 次数 return count($matches[0]); } /** * 向界面输出数据 * @param type $log * @param type $spider * @return type */ function send_tr($log, $spider) { $html = ""; $arr = httpinfo_w3c($log, $spider); for ($i = 0; $i < count($arr); $i++) { $html.=" <tr> <td>{$arr[$i][0]} {$arr[$i][1]}</td> <td>{$arr[$i][3]}</td> <td>{$arr[$i][4]}</td> <td>{$arr[$i][8]}</td> <td>{$arr[$i][9]}</td> <td>{$arr[$i][10]}</td> </tr>"; } return $html; } /** * 输出选择log列表 * @global type $file_list * @return string */ function send_select() { global $file_list; $break = 30; $html = ""; $q = 0; for ($i = 0; $i < count($file_list); $i++) { $html .= "<option value=\"$file_list[$i]\">{$file_list[$i]} - " . Send_size($file_list[$i]) . "</option>"; if ($i > $break) { break; } } return $html; } /** * 输出文件大小 * @global string $path * @param type $log_name * @return type */ function Send_size($log_name) { global $path; $size = (int) filesize($path . $log_name); $size = format_bytes($size); return $size; } function format_bytes($size) { $units = array(' B', ' KB', ' MB', ' GB', ' TB'); for ($i = 0; $size >= 1024 && $i < 4; $i++) $size /= 1024; return round($size, 2) . $units[$i]; } function chart_1_spider_list($spider) { global $file_list, $path; $list = ""; for ($i = 0; $i < 10; $i++) { $log = file_get_contents($path . "/" . $file_list[$i]); $count = spider_count($log, $spider); $list = $count . "," . $list; } return $list; } ?> <html> <head> <title>爱资料php日志分析工具v11</title> <script src="http://www.apizl.com/public/soft/chart/js/jquery.1.9.1.min.js"></script> <script src="http://www.apizl.com/public/soft/chart/echarts.min.js"></script> </head> <body> <a href=""><h3>爱资料php日志分析工具v11</h3></a> 选择日志:<select onchange=" GetLog(this)"> <?php echo send_select(); ?> </select> <a href="#baidu">百度 - <?php echo spider_count($log, "Baiduspider"); ?>次</a> | <a href="#sm">神马 - <?php echo spider_count($log, "YisouSpider"); ?>次</a> | <a href="#google">谷歌 - <?php echo spider_count($log, "Googlebot"); ?>次</a> | <a href="#360">360 - <?php echo spider_count($log, "360Spider"); ?>次</a> | <a href="#sogou">搜狗 - <?php echo spider_count($log, "Sogou"); ?>次</a> <a href="#" onclick="show_chart_()">展开统计图</a> <div id="chart" style="display: ;"> <div id="size_spider" style="width: 600px;height:400px;"></div> </div> <h4>------------------------------------------------------------------------</h4> <h2 onclick="show('baidu');">百度 - <?php echo spider_count($log, "Baiduspider"); ?>次</h2> <table border=1 id="baidu" style="display: none;"> <?php echo send_tr($log, "Baiduspider"); ?> </table> <h2 onclick="show('sm');">神马 - <?php echo spider_count($log, "YisouSpider"); ?>次</h2> <table border=1 id="sm" style="display: none;"> <?php echo send_tr($log, "YisouSpider"); ?> </table> <h2 onclick="show('google');">谷歌 - <?php echo spider_count($log, "Googlebot"); ?>次</h2> <table border=1 id="google" style="display: none;"> <?php echo send_tr($log, "Googlebot"); ?> </table> <h2 onclick="show('360');">360 - <?php echo spider_count($log, "360Spider"); ?>次</h2> <table border=1 id="360" style="display: none;"> <?php echo send_tr($log, "360Spider"); ?> </table> <h2 onclick="show('sogou');">搜狗 - <?php echo spider_count($log, "Sogou"); ?>次</h2> <table border=1 id="sogou" style="display: none;"> <?php echo send_tr($log, "Sogou"); ?> </table> <script> $(function() { $("select").val("<?php echo $log_name; ?>"); }) function show(id) { var status = $("#" + id).css("display"); if (status == "none") { $("#" + id).css("display", "block"); } else { $("#" + id).css("display", "none"); } } function GetLog(t) { var name = $(t).val(); window.location = '?log=' + name; } var myChart = echarts.init(document.getElementById('size_spider')); // 指定图表的配置项和数据 var option = { title: { text: '搜索引擎来访<?php echo date("y-d-m")?>' }, tooltip: { trigger: 'axis' }, legend: { data: ['百度', '神马', '谷歌', '360', '搜狗'] }, toolbox: { feature: { saveAsImage: {} } }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, xAxis: [ { type: 'category', boundaryGap: false, data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '<?php echo date("d-m")?>'] } ], yAxis: [ { type: 'value' } ], series: [ { name: '百度', type: 'line', stack: '总量', areaStyle: {normal: {}}, data: [<?php echo chart_1_spider_list("Baiduspider"); ?>] }, { name: '神马', type: 'line', stack: '总量', areaStyle: {normal: {}}, data: [<?php echo chart_1_spider_list("YisouSpider"); ?>] }, { name: '谷歌', type: 'line', stack: '总量', areaStyle: {normal: {}}, data: [<?php echo chart_1_spider_list("Googlebot"); ?>] }, { name: '360', type: 'line', stack: '总量', areaStyle: {normal: {}}, data: [<?php echo chart_1_spider_list("360Spider"); ?>] }, { name: '搜狗', type: 'line', stack: '总量', areaStyle: {normal: {}}, data: [<?php echo chart_1_spider_list("Sogou"); ?>] } ] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); function show_chart_() { var none = $("#chart").css("display"); if (none == "block") { $("#chart").css("display", "none"); } else { $("#chart").css("display", "block"); } } </script> </body> </html>
关键字词: