在php中生成的大文件的索引问题

I have a problem to retrieve the value of large files (> 7GB). once I find out the solution, mostly using fgets (). examples of such cases: My file:

#CHROM  POS ID  REF ALT
1   8   rs392108184 T   G
4   91  rs122936913 G   T

my code:

<?php
    //(1)
    echo "(1)";
    $data = file_get_contents("data/ncbi/5.vcf");
    $data = explode("
", $data);
    echo '<pre>';
    print_r($data);
    echo '</pre>';

    //(2)
    echo "(2)";
    $handle = @fopen("data/ncbi/5.vcf", "r");
    if ($handle) {
        while (($buffer = fgets($handle, 4096)) !== false) {
            $buffer = explode("
", $buffer);
            echo '<pre>';
        print_r($buffer);
        echo '</pre>';
        }
        fclose($handle);
    }
?>

output:

(1)
Array
(
    [0] => #CHROM   POS ID  REF ALT
    [1] => 1    8   rs392108184 T   G
    [2] => 4    91  rs122936913 G   T
)
(2)
Array
(
    [0] => #CHROM   POS ID  REF ALT
    [1] => 
)
Array
(
    [0] => 1    8   rs392108184 T   G
    [1] => 
)
Array
(
    [0] => 4    91  rs122936913 G   T
    [1] => 
)

if i use (1), output as I want but can not use for large files. whereas if I use (2), can be used for large files, but the output as it is not what I wanted, because iteration is not clear. I want to use large files and the output could be like this.

Array
    (
        [0] => #CHROM   POS ID  REF ALT
        [1] => 1    8   rs392108184 T   G
        [2] => 4    91  rs122936913 G   T
    )

is there any solution?

If you run out of memory trying to load the whole file into memory, count the lines in your own code:

$linenum = 0;
while ($line = fgets($handle)) {
    echo "<pre>($linenum) => $line</pre><br>";
    $linenum++;
}