I have a file a csv file (made as .txt) that I am currently parsing right now, but the file is about 350mb uncompressed. When it’s zipped, it shows in the zip file as 23mb. My system completely freezes when I try to parse the 350mb file. I store the lines in an array like this. The first row are the headings.
$fh = fopen($inputFile, 'r');
$contents = fread($fh, filesize($inputFile)); // 5KB
fclose($fh);
//$contents = str_replace('"','',$contents);
$fileLines = explode("\n", $contents); // explode to make sure we are only using the first line.
Then I go through each line to insert it in a loop into mySQL. Since the file is about 350mb, would there be a way to parse it from the .zip file like .zip_filename.txt or would that even make a difference at all?
The file is too large to insert directly into mysql through the import method.
Use the built in function fgetcsv:
Also use multi insert if possible. Instead of running multiple queries:
Building one query like this is much quicker:
By the way, you can also load a file directly into mysql: