In the context of PHP development, what are some common pitfalls to be aware of when working with large files or datasets?

When working with large files or datasets in PHP, common pitfalls include memory exhaustion due to loading the entire file into memory at once, slow processing times, and potential server crashes. To mitigate these issues, consider reading the file line by line or in chunks, processing data incrementally, and optimizing code for memory efficiency.

// 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.";
}