I have a 1.3 GB text file that I need to extract from PHP. I researched it and came up with several different ways to do what I need to do, but, as always, after a little clarification about which method will be better, or if better, which I don’t know about?
The information I need in a text file is only the first 40 characters of each line, and the file contains about 17 million lines. 40 characters from each line will be inserted into the database.
The following are the methods below:
set_time_limit(0);
ini_set('memory_limit', '-1');
$handle = @fopen('C:\Users\Carl\Downloads\test.txt', 'r');
if($handle) {
while(($buffer = fgets($handle)) !== false) {
$insert[] = substr($buffer, 0, 40);
}
if(!feof($handle)) {
}
fclose($handle);
}
It reads each row above at a time and receives the data, I have all the database inserts sorted, doing 50 inserts ten times in the transaction.
, file() , foreach ? , 17 .
, , , , script header?
? , ?
script wamp, , script 0. , script ?