ini_set ('memory_limit', '1024M');
$log = file_get_contents('upstream.log');//读取nginx日志
$log=explode("\n",$log);
$p = '/^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s-\s(.*)\s\[(.*)\]\s"(.*)\"\s(\d{3})\s(\d+)\s"(.*)"\s\"(.*)\"(.*)$/u';//正则分析
foreach($log as $k=>$v){
preg_match($p,$v,$a_match);
if($a_match[8]='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36'){//提取特征匹配
//echo $a_match[1]."\n";
$host[]=$a_match[1];//提取ip
}
//var_dump($a_match);
}
print_r(array_unique($host));