I have the following code
$file="postcodes.csv";
$csv= file_get_contents($file);
$array = array_map("str_getcsv", explode("\n", $csv));
$json = json_encode($array);
print_r($json);
postcodes.csv is 603MB in size, so a large file.
In php.ini, if I have
memory_limit=1024M
I get the error
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 256 bytes) in ...
If I increase the memory limit to 2056, I get the error
Fatal error: Out of memory (allocated 1919680512) (tried to allocate 36 bytes) in...
It is similar if I change it to -1.
So how can I load this csv file without having memory issues?
Thanks
memory_limitto at least 4 * or 8 * the number of characters in the input file, depending on your architecture, and see whether that helps. Disclaimer: I've not done file-reading in PHP yet. - underscore_d