php - fputcsv does not work with large arrays -


i'm using fputcsv (obviously) create csv file of table in application. post 2d array of data to:

function formatoutput(&$vals, $key){     foreach($vals $row=>&$cell){         $cell = str_replace('"', '""', $cell);          $cell = str_replace(array("\n",','), '', $cell);      } }  function outputcsv($array) {     $outstream = fopen("php://output", "w");     function __outputcsv(&$vals, $key, $filehandler) {         fputcsv($filehandler, $vals);     }     array_walk($array, "formatoutput");     array_walk($array, "__outputcsv", $outstream);     fclose($outstream); }  outputcsv(unserialize($_post['data'])); 

so, each line in array, appends csv file. well, works fine until pass in array around 500 or more lines.

is there size limit when using function? documentation doesn't mention anything. or there php setting limit size?

there question here: is there file size limit when creating csv file using php , mysql?

which asks same thing, though there marked answer, doesn't explain possible solutions. states:

"sounds problem environment settings - not code or limitation of technologies."

php loads variables these memory. , every script has maximum amount of memory allowed use, based on php.ini settings.

also, when variables copied, can take double space in memory. source memory, , destination memory. i'm not sure internals of fputcsv, it's possible entire array being converted csv "object" internally, written out file.

so, remember you're possibly doubling memory usage time copy.

in least, check "memory_limit" in php.ini. if need increase 1 script in particular, can set in script with:

ini_set('memory_limit','16m'); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -