php - Paged query exhausting memory -
i want export big table csv, impossible select data @ once , export, open file handle writing , call function takes query , loops through different pages, i'm calling page size of 20 small, after time of execution (maybe 30 minutes), leads error:
fatal error: allowed memory size of 100663296 bytes exhausted (tried allocate 85 bytes) in /usr/home/www/wp-includes/wp-db.php on line 1402
this function, $fichero alraedy opened file handle, $pagina_size had value of 20 in last test:
function sql2csv_streamed($fichero, $sql, $pagina_size=50) { global $wpdb; $limite1 = 0; $limite2 = $pagina_size-1; $sql_pagina = $sql . " limit $limite1,$limite2"; error_log($sql_pagina); // add values in table while ($rssearchresults = $wpdb->get_results($sql_pagina, array_a)) { foreach ( $rssearchresults $res ) { fputcsv ($fichero, $res , ";"); } $limite1 += $pagina_size; $limite2 += $pagina_size; $sql_pagina = $sql . " limit $limite1,$limite2"; error_log($sql_pagina); } }
thank you
Comments
Post a Comment