php - Is file() good for average of 5,000 - 6,000 lines or I must edit it for better performance? -


Text after "

This is an exact copy of the question:

  • 1 answer

text file (from which of my Fashion grab information) is being built at 00:00 every day and my application starts slowly during the day to add lines to lines as a log file. The file is approximately 1MB and there are approximately 6,000 lines at the end of the day, so it is not really a small file for a game / kills and the script can be accessed by a lot of users checking the log statistics to display the latest 21 deaths The function is grabbing the latest 21 lines from the text file. My question is how can I create scripts with better performance because file () is actually reading the entire file through lines, so do the What is a better way? If many people use log pages to display this information from text file or for 6000 lines it can affect performance, should it be all good? The file is in plain text form .txt format and these are an example lines from the file:

  1,42,16, 201, stackoverflow_user, 1, 6,762,160, 39,799 , 9,817,242, 6,762,160, 39,884, 10,010,545, stackoverflow_user, 2, 1,351,147, 1165, 483,259, 1351147, 1115, 241630, 0, 1,46,27, 201, [Staccorflower_Users | Stackoverflow_userother], 1, 4078465, 2869 9, 159 4830, 4078465, 287036, 1643156, Stackeverflo_user, 2, 1357147, 1115, 241630, 1357147, 1065, 120815, 0  

< Strong> My Function:

  # Read a file in an array $ rows = file ('C: /path/to/file.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); # Flip our array, so the last lines of the file are the first. $ Lines = array_reverse ($ rows); $ N = 1; $ Wanted = 21; # Or else you want several lines $ content = ''; Foreign currency ($ lines as $ l) {# Treat the data as values ​​separated by commas $ arr = explosion (",", $ l); # If there are multiple values ​​in column 5, take it first (preg_match ("/æ[(.+?) \ | /", $ Arr [4], $ matches) $ arr [4] = $ matches [1 ]; } # Ir [4] is similar to ARR [12]? If these are not equal, then use these values: $ arr = array ($ arr [4]! == $ arr [12]) {# These values ​​are not equal, then $ value = array ('rank-pause' = & gt; $ n ++, ' Rank-name '= & gt; $ arr [4],' rank-DMUz '=> $ arr [12]); $ Content = Template :: Load ('Ranking DM-'. ($ N% 2 == 1? 2: 1), $ data); } # Did we get enough data? If ($ n === $ wanted) {break; }} $ This-> Content = Template :: Load ('user_rankingsdm', array ('ranking' => gt; $ content)); }  

After

If you are running on a Unix system, think of calling the tail

  & lt ;? Php $ file = log.txt; $ Last_lines = `tail -n 21 $ file`; // Bettix system calls print_r ($ last_lines);  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -