What is the common issue with importing large files in PHP and how can it be resolved?
When importing large files in PHP, a common issue is hitting the memory limit or execution time limit, causing the script to fail. This can be resolved by increasing the memory limit and execution time in the PHP configuration or by using methods like reading the file line by line instead of loading the entire file into memory at once.
// Increase memory limit and execution time
ini_set('memory_limit', '256M');
ini_set('max_execution_time', 300);
// Read file line by line
$file = fopen('large_file.txt', 'r');
while (!feof($file)) {
$line = fgets($file);
// Process each line here
}
fclose($file);