What is the best approach for importing a large file with up to 300,000 lines in PHP?

When importing a large file with up to 300,000 lines in PHP, it is best to read the file line by line to avoid memory issues. This can be achieved by using functions like fopen, feof, fgets, and fclose to efficiently process each line of the file without loading the entire content into memory at once.

$file = fopen('large_file.txt', 'r');

if ($file) {
    while (($line = fgets($file)) !== false) {
        // Process each line here
    }
    fclose($file);
} else {
    echo "Error opening file.";
}