PHP reads a certain line of data from a large file text TEXT

高洛峰
Release: 2016-11-28 16:43:21
Original
1669 people have browsed it

function get_line($file,$line) {
    $fp = fopen($file,'r');
    $i = 0;
    while(!feof($fp)) {
        $i++;
        $c = fgets($fp);
        if($i==$line) {
            echo $c;
            break;
        }
    }
}
Copy after login

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


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!