Every medium and large website will have a log. The log is stored in ***.log in the form of text. The log generally stores the operation overview of the website, basic information of the user, user usage habits and other information. Obviously, analyzing logs is an urgent matter, and logs can have tens of thousands or even hundreds of thousands of lines. How can such a large file be analyzed?
You can analyze each line by looping the log. The following is the code:
Php code
$txt_file = $savepath . '/report.log'; $file_handler = fopen($txt_file, 'r');//以可读方式打开文件 while (!feof($file_handler)) { $con = fgets($file_handler); //$con就是每一行的内容,在这里进行必要的分析 }