php脚本完成篇

#刚才睡不着,又去看了下手册上面的函数,呼呼~终于找到一个比较理想的解决方案了(对我这个小菜鸟来说)

#实现统计nginx日志的访问IP和对应IP的访问次数:

#!/usr/bin/php
<?php
echo "      IP\t       count\n--------------------------------\n";
$i=0;
$File_ = fopen("access.log","r");
        while(!feof($File_)){
                $Line = fgets($File_);
                $NEW_Line = preg_replace("/ .*/","",$Line);
                $Con[$i]=$NEW_Line;
                $i++;
                }
                fclose($File_);
                $qq=array_count_values($Con);
                asort($qq,SORT_NUMERIC);
                foreach($qq as $b => $c){
                if($b != ""){
                $b=trim($b);
                echo "$b\t\t$c\n";
                }
                }
?>
执行效率:

real    0m0.669s
user    0m0.552s
sys     0m0.102s

 

你可能感兴趣的:(PHP,nginx,职场,休闲)