What are common issues when processing large files in PHP scripts, and how can they be addressed?

Issue: Memory exhaustion can occur when processing large files in PHP scripts due to loading the entire file into memory at once. This can lead to performance issues and potential crashes. To address this, it's recommended to read the file line by line or in chunks to reduce memory usage.

// Example of reading a large file line by line
$filename = 'large_file.txt';
$handle = fopen($filename, 'r');

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

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