Mar  8 12:51:26 10.10.255.5 haproxy[4844]: 124.240.36.246:10313[10.10.255.5:60343]->58.252.186.10:80[58.252.186.10:80] [08/Mar/2012:12:51:26.392] http_check tcp_proxy/<NOSRV> 1/28/72 163 -- 608/608/541/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4843]: 124.240.68.12:2621[10.10.255.5:50753]->110.75.183.212:80[110.75.183.212:80] [08/Mar/2012:12:51:23.219] http_check tcp_proxy/<NOSRV> 56/37/3247 248 -- 498/498/444/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4838]: 124.240.52.95:54071[10.10.255.5:46638]->114.112.36.113:80[114.112.36.113:80] [08/Mar/2012:12:50:56.348] http_check tcp_proxy/<NOSRV> 0/45/30118 569 cD 464/464/401/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4843]: 124.240.20.142:2373[10.10.255.5:44038]->121.11.67.146:80[121.11.67.146:80] [08/Mar/2012:12:51:26.411] http_check http_image/<NOSRV> 32/0/12/11/55 200 225 - - ---- 497/497/10/0/0 0/0 {ctc.qzs.qq
.com|http://user.qzone.qq.com/942154386/infocenter} "GET /ac/b.gif?delay HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4840]: 124.240.20.142:2372[10.10.255.5:44037]->121.11.67.146:80[121.11.67.146:80] [08/Mar/2012:12:51:26.411] http_check http_image/<NOSRV> 32/0/12/12/56 200 225 - - ---- 538/538/14/0/0 0/0 {ctc.qzs.qq
.com|http://user.qzone.qq.com/942154386/infocenter} "GET /ac/b.gif?delay HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4840]: 124.240.71.64:1583[10.10.255.5:36850]->122.143.24.136:80[122.143.24.136:80] [08/Mar/2012:12:51:26.262] http_check tcp_proxy/<NOSRV> 9/89/208 461 -- 537/537/486/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4843]: 124.240.20.142:2374[10.10.255.5:44045]->121.11.67.146:80[121.11.67.146:80] [08/Mar/2012:12:51:26.411] http_check http_image/<NOSRV> 41/0/12/12/65 200 225 - - ---- 496/496/9/0/0 0/0 {ctc.qzs.qq.
com|http://user.qzone.qq.com/942154386/infocenter} "GET /ac/b.gif?delay HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4838]: 203.132.32.23:54108[10.10.255.5:50154]->123.125.73.134:80[123.125.73.134:80] [08/Mar/2012:12:51:26.312] http_check tcp_proxy/<NOSRV> 1/72/164 485 -- 463/463/400/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4842]: 10.12.225.19:23304[10.10.255.5:59492]->60.28.126.35:80[60.28.126.35:80] [08/Mar/2012:12:51:26.297] http_check tcp_proxy/<NOSRV> 10/78/180 378 -- 519/519/465/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4844]: 124.240.21.95:64471[10.10.255.5:50784]->112.91.128.240:80[112.91.128.240:80] [08/Mar/2012:12:51:26.400] http_check http_image/<NOSRV> 11/0/33/33/78 200 1578 - - ---- 613/613/18/0/0 0/0 {img04.t
aobaocdn.com|http://cart.taobao.com/my_cart.htm?from=mini&ad_id=&am_id=&cm_id=&pm_id=} "GET /tps/i4/T1YTGkXg8hXXXXXXXX-19-150.png HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4844]: 124.240.22.45:1468[10.10.255.5:34491]->58.249.61.228:80[58.249.61.228:80] [08/Mar/2012:12:51:26.422] http_check http_image/<NOSRV> 1/0/27/29/57 200 757 - - ---- 612/612/17/0/0 0/0 {img.t.sinajs
.cn|http://photo.weibo.com/messages/comments} "GET /t4/style/images/common/ico_talstat.png HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4844]: 124.240.22.45:1469[10.10.255.5:34492]->58.249.61.228:80[58.249.61.228:80] [08/Mar/2012:12:51:26.422] http_check http_image/<NOSRV> 1/0/28/28/57 200 688 - - ---- 611/611/16/0/0 0/0 {img.t.sinajs
.cn|http://photo.weibo.com/messages/comments} "GET /t4/style/images/common/ico_toplistof.gif HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4844]: 124.240.17.207:2029[10.10.255.5:48475]->112.90.137.50:80[112.90.137.50:80] [08/Mar/2012:12:51:26.337] http_check tcp_proxy/<NOSRV> 10/30/144 286 -- 610/610/542/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4839]: 124.240.21.189:1486[10.10.255.5:55401]->112.95.234.18:80[112.95.234.18:80] [08/Mar/2012:12:51:26.383] http_check tcp_proxy/<NOSRV> 11/31/98 68 -- 429/429/389/0/0 0/0
Mar  8 12:51:26 10.10.255.5 haproxy[4842]: 203.132.34.10:2833[10.10.255.5:53037]->112.90.172.55:80[112.90.172.55:80] [08/Mar/2012:12:51:23.375] http_check http_image/<NOSRV> 41/0/34/3034/3109 200 363 - - CD-- 518/518/15/0/0 0/0 {static.
hudong.com|http://www.hudong.com/newtop/lmqy.html?hf=lmqiyou&pf=lmqiyou3385&WebID=3385&AdsFeeStatus=2} "GET /83/81/18100000002521133101817908103.jpg HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4844]: 124.240.22.45:1471[10.10.255.5:34500]->58.249.61.228:80[58.249.61.228:80] [08/Mar/2012:12:51:26.422] http_check http_image/<NOSRV> 10/0/27/29/66 200 1035 - - ---- 613/613/20/0/0 0/0 {img.t.sina
js.cn|http://photo.weibo.com/messages/comments} "GET /t4/style/images/common/ico_handpick.png HTTP/1.1"
Mar  8 12:51:26 10.10.255.5 haproxy[4843]: 124.240.20.142:2375[10.10.255.5:44056]->121.11.67.146:80[121.11.67.146:80] [08/Mar/2012:12:51:26.411] http_check http_image/<NOSRV> 55/0/11/12/78 200 225 - - ---- 503/503/10/0/0 0/0 {ctc.qzs.qq
.com|http://user.qzone.qq.com/942154386/infocenter} "GET /ac/b.gif?delay HTTP/1.1"
=====
读取后存入数组,把58.249.61.228:80取出作为键,1作为值,遇到相同的值就加1.

解决方案 »

  1.   

    substr_count($string, '58.249.61.228:80');
      

  2.   

    你的文件应该非常大,不可一次性读取
    $fn = '你的文件名';
    $fp = fopen($fn, 'r') or die("文件 $fn 打开失败");
    while($s = fgets($fp)) {
      preg_match('/\[[\d.:]+\].+\[([\d.:]+)\]/', $s, $r);
      if(empty($r[1])) continue;
      $res[$r[1]]++;
    }
    fclose($fp);print_r($res);
    你示例的数据的结果Array
    (
        [58.252.186.10:80] => 1
        [110.75.183.212:80] => 1
        [114.112.36.113:80] => 1
        [121.11.67.146:80] => 4
        [122.143.24.136:80] => 1
        [123.125.73.134:80] => 1
        [60.28.126.35:80] => 1
        [112.91.128.240:80] => 1
        [58.249.61.228:80] => 3
        [112.90.137.50:80] => 1
        [112.95.234.18:80] => 1
        [112.90.172.55:80] => 1
    )
      

  3.   

    PHP Notice:  Undefined index: 58.55.231.97:80 in /var/log/count.php on line 7
    PHP Notice:  Undefined index: 116.54.32.170:80 in /var/log/count.php on line 7
    PHP Notice:  Undefined index: 115.54.234.36:80 in /var/log/count.php on line 7
    PHP Notice:  Undefined index: 119.36.58.110:80 in /var/log/count.php on line 7
    PHP Notice:  Undefined index: 118.116.95.247:80 in /var/log/count.php on line 7
    PHP Notice:  Undefined index: 14.145.131.168:80 in /var/log/count.php on line 7
    ==================
    现在报这个错,我又改不了服务器配置,只好定义了。
      

  4.   

    你在干什么?
    那几个 ip 并未出现在数组的键中,你怎么能这样指名道姓的用呢?你是在分析日志,分析出什么结果就是什么结果如果你是有着对性的检查特定 ip
    那要这么做
    $ip = '58.55.231.97:80';
    if(array_key_exists($ip, $ar)) {
      //存在时的处理
    }else {
      //不存在时的处理
      

  5.   

      首先,这个不是错误,是warning。所以如果服务器不能改,每个变量使用前应当先定义。 
        方法1:服务器配置修改 
        修改php.ini配置文件,error_reporting = E_ALL & ~E_NOTICE 
        方法2:对变量进行初始化,规范书写(比较烦琐,因为有大量的变量)。但还没有找到好定义方法,望大家指教 
        方法3:每个文件头部加上:error_reporting(0); 如果不行,只有打开php.ini,找到display_errors,设置为display_errors = Off。以后任何错误都不会提示。 
        方法4 :做判断:isset($_GET["page"])      if-else判断     或者加上''@''表示这行如果有错误或是警告不要輸出
         如:@$page=$_GET["page"] 
        方法5:file1.php文件把$xx变量付一个值,用post传递给file2.php,
         如果file2.php没有$xx的定义,而直接使用$yy=$xx; 系统就会报错:"undifined variaable $xx", 如果file2.php的文件开始用$xx="";定义,那么file1.php的$xx值就传不过来了! 
        file2.php里可以这样
         if(!isset($xx)) $xx="";