I'm trying to read a CSV file that has 800000 line using PHP, but i got this Error:
Allowed memory size of 536870912 bytes exhausted (tried to allocate 4096 bytes)
How could i fix it?
I'm trying to read a CSV file that has 800000 line using PHP, but i got this Error:
Allowed memory size of 536870912 bytes exhausted (tried to allocate 4096 bytes)
How could i fix it?
You can read it by chunk.
<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}