$v)">
时间:2021-07-01 10:21:17 帮助过:23人阅读
$logsArr){ echo "---------------------------{$key}-------------------------------" .PHP_EOL; foreach($logsArr as $k => $v){ echo $k . " [num : ".count($v)."]" .PHP_EOL; foreach ($v as $phpfile){ $n = explode(":",$phpfile); $s = explode(" ",$n[0]); if($s[2] && $s[2] != 'unknown' && $s[2] != 'dump'){ // echo "======> " . $s[2] . "[ Line: {$n[1]}]". PHP_EOL; $md5_key = md5($s[2].$n[1]); if(array_key_exists($md5_key,$stats[$key])){ $stats[$key][$md5_key] = array( 'main'=>$k, 'file'=> $s[2], 'line'=> $n[1], 'code'=> $s[1], 'num'=> $stats[$key][$md5_key]['num'] + 1 ); } else { $stats[$key][$md5_key] = array( 'main'=>$k, 'file'=> $s[2], 'line'=> $n[1], 'code'=> $s[1], 'num'=>1 ); } } } } } echo PHP_EOL; echo PHP_EOL; echo PHP_EOL; echo "Create json file: slowlog.json" . PHP_EOL; file_put_contents('slowlog.json',json_encode($stats)); echo "Success!" . PHP_EOL; echo "http://tool.lu/json/"; function loadFile( $file ){ $str = file_get_contents($file); $arr = explode("\n",$str); $g = 0; $data = array(); foreach($arr as $val){ if( $val ){ $data[ $g - 1][] = $val; } else { $g++; } } $logs = array(); foreach( $data as $key => $log){ foreach($log as $k => $l){ $time = $data[$key][0]; $phpfile = $data[$key][1]; $p = "#\[(.*?) (.*?)\] \[(.*?)\] pid (.*?)#"; preg_match($p,$data[$key][0],$arr); $time = $arr[1]; if( $data[$key][0] != $l ){ if( $phpfile != $l ){ $logs[ $time ][$phpfile][] = $l; } } } } return $logs; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了slowlog分析工具 v 10,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。