Question: What php function should I use to count the 5th line of a large file as the 5th line is the bandwidth?

Example of data:

```
103.239.234.105 -- [2007-04-01 00:42:21] "GET articles/learn_PHP_basics HTTP/1.0" 200 12729 "Mozilla/4.0"

```

Answer: 
If you want to read *every 5th line*, you could use an [`SplFileObject`](http://php.net/splfileobject) to make life a little easier (than the `fopen/fgets/fclose` family of functions).

```
$f = new SplFileObject('myreallybigfile.txt');

// Read ahead so that if the last line in the file is a 5th line, we echo it.
$f->setFlags(SplFileObject::READ_AHEAD);

// Loop over every 5th line starting at line 5 (offset 4).
for ($f->rewind(), $f->seek(4); $f->valid(); $f->seek($f->key()+5)) {
    echo $f->current();
}

```
Open the file into a handle:

```
$handle = fopen("someFilePath", "r");

```

Then read the first 5 lines, and only save the fifth:

```
$i = 0;
$fifthLine = null;
while (($buffer = fgets($handle, 4096)) !== false) {
    if $i++ >= 5) {
        $fifthLine = $buffer;
        break;
    }
}
fclose($handle);
if ($i < 5); // uh oh, there weren't 5 lines in the file!
//$fifthLine should contain the 5th line in the file

```

Note that this is streamed so it doesn't load the whole file.