#提供交互式登录,根据需求统计nginx日志,比如统计访问次数,访问源地址列表清单,页面状态等(页面状态的没有复制进来,太长了,写的太菜了)。。
#!/usr/bin/php
<?php
$i=0;
function read() {
$fp = fopen("/dev/stdin", "r");
$input = fgets($fp, 255);
fclose($fp);
return $input;
}
function put (){
$i=0;
echo " IP\t count\n--------------------------------\n";
$File_ = fopen("access.log","r");
while(!feof($File_)){
$Line = fgets($File_);
$NEW_Line = preg_replace("/ .*/","",$Line);
$Con[$i]=$NEW_Line;
$i++;
}
fclose($File_);
$NEW_array=array_count_values($Con);
asort($NEW_array,SORT_NUMERIC);
foreach($NEW_array as $Key => $Value){
if($Key != ""){
$Key=trim($Key);
echo "$Key\t\t$Value\n";
}
}
}
echo "Please Enter status or count :";
$count=read();
$count=trim($count);
switch($count){
case "count":
put();
break;
default :
echo "zi ji bu chong bei\n";
}
?>
转载于:https://blog.51cto.com/unixlike/666231