What are the best practices for reading a file line by line in PHP, especially when dealing with large files?

When dealing with large files in PHP, it is important to read them line by line to avoid memory issues. One way to do this is by using the `fgets()` function in a loop until the end of the file is reached. This allows you to process the file one line at a time without loading the entire file into memory.

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

if ($handle) {
    while (($line = fgets($handle)) !== false) {
        // Process each line here
        echo $line;
    }

    fclose($handle);
} else {
    echo "Error opening the file.";
}