Home >Backend Development >PHP Tutorial >PHP reads a certain line of data from a large file text TEXT
function get_line($file,$line) { $fp = fopen($file,'r'); $i = 0; while(!feof($fp)) { $i++; $c = fgets($fp); if($i==$line) { echo $c; break; } } }
The efficiency of this method still needs to be tested
In an apache log file (450M)
Reading the 20th line is very fast 0.001039981842041
Reading the 200th line 0.0033199787139893
It takes 0.30908 to read the 20,000th line 799171448 seconds About
Reading the 200,000th row 2.5622429847717 seconds has reached the point of being unbearable