I am using adwords reporting api to get all ad's and keyword's info for all the adwords account. Currently account count is 1363. Reporting api generates a CSV which I am parsing it to Array below is the function. After parsing a good 1180 account it gives an error
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytes) .
I have set memory to 512MB (which I believe is a lot).
The error comes on this line
$line_of_text[] = fgetcsv($file_handle, 1024);
private function convertCSVtoArray($csvFile){
try {
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle) ) {
$line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return $line_of_text;
} catch (Exception $e) {
log_message('Exception in convertCSVtoArray()', $e);
throw new Exception('Exception in convertCSVtoArray => '.$e);
}
}
The above function is called from a method
$data = $this->convertCSVtoArray($filePath);
I believe, there is a memory leak somewhere in the given code which is eating all the memory.
Please suggest if there is any solution.