I need to write almost 109,392 rows to CSV file and currently I am doing it like this
//open raw memory as file, no need for temp files
$tempMemory = fopen('php://temp', 'w');
//default php csv handler
foreach ($inputArray as $line) {
fputcsv($tempMemory, $line, $delimiter);
}
//rewrind the "file" with the csv lines
fseek($tempMemory, 0);
//modify header to be downloadable csv file
header('Content-Type: application/csv');
header('Content-Disposition: attachement; filename="' . $outputFileName . '";');
//send file to browser for download
fpassthru($tempMemory);
The problem here is that it is very slow and I am not getting all the rows inserted. The array size of $inputArray is 109,392 but only 50K rows are there in the CSV file produced. What is the best way of doing this ?
flush(), not sure if ??rewind()` takes care of that.