Reputation: 4693
I have a large set of results as an array from a cakePHP model for a csv export. I have been formatting using a loop as shown below. As the number of records grow, this is becoming too slow and giving time out errors. Is there a better way to do this using either cakephp hash or php array functions?
foreach($people as $person){
array_push($results, array(
'SchoolName'=> $person['School']['name'],
'SchoolRef' => $person['School']['ref'],
'firstName' => $person['Person']['firstname'],
'LastName' => $person['Person']['lastname'],
'Year1' => $person['Person']['year_1'],
'StudentID' => $person['Person']['studentid'],
'Email' => $person['Person']['email']
));
}
Upvotes: 0
Views: 86
Reputation: 15159
If you're just outputting to CSV, why not try outputting directly from MySQL (or whichever database you're using).
Eg. http://ariejan.net/2008/11/27/export-csv-directly-from-mysql/
Alternatively, if the data doesn't change, you might be able to presummarize the existing output. So, if you had 10,000 students the last time you outputted the CSV, you could save that CSV and just append the new records. If they do change, you could add a hash of all fields to each record.
Also, if the data doesn't have to be up to the minute accurate, you could presummarize on a daily basis (or whatever interval works for you).
However, without clear indication of where you're at (in terms of record sizes and timeouts), and without a clear idea of where you'd like to be, its difficult to make a specific recommendation.
Upvotes: 1