Are there any best practices for efficiently counting lines in a file using PHP, especially for large files?

When counting lines in a file using PHP, especially for large files, it is important to use efficient methods to avoid memory issues. One approach is to use a loop to read the file line by line instead of loading the entire file into memory at once. Another method is to use the `fgets()` function to read lines from the file handle. Additionally, you can optimize the process by using functions like `feof()` to check for the end of the file.

$filename = 'large_file.txt';
$lineCount = 0;

$handle = fopen($filename, 'r');
if ($handle) {
    while (!feof($handle)) {
        $line = fgets($handle);
        if ($line !== false) {
            $lineCount++;
        }
    }
    fclose($handle);
}

echo "Total number of lines in the file: " . $lineCount;