php - 使用fopen时允许的X字节内存大小耗尽

I have code similar to the following:

<?php
ini_set('memory_limit', '2048M');
$dates = Array('14-JUL-14','13-JUL-14','12-JUL-14', ...etc )
$filename = '/home/me/query-output_all.csv';
$fp = fopen($filename, 'w');
foreach ($dates as $currday) {
    $query = "--sql query with large result set";

    //perform query
    $rows = $dbo->query($dbh,$query); //set earlier. dbh = oci_connect()

    //add rows to file
    foreach ($rows as $value) {
        //add date key to $value
        array_unshift($value, $currday);
        fputcsv($fp, $value);
    }
}
fclose($fp); 
?>

I am getting the following error when my $dates array contains 90 or so dates:

Fatal error: Allowed memory size of 2147483648 bytes exhausted

After researching, I believe that this is caused by the $fp variable becoming too large. Is there a way that I can write to a file, like above, without have to worry about this size limiation? (note - increasing memory_limit is a temporary fix, but not long term, considering that it's possible that I will be querying to 10+ gigabytes of total data at some point.)