3
I’m developing an application where, in a report, I need to print something around 50,000 lines. When having run SELECT error occurs:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 24 bytes) in C: wamp www simplaFramework System Framework Model.class.class.php on line 884.
The following query result is being saved in a array
'cause I’ll treat you later:
$data = array();
$count = 0;
while ($row = $q->fetch($pdo_fetch)) {
$data[] = $row;
++$count;
}
My idea was to divide the result into 2 or more arrays whenever I get an X amount of memory usage.
For example: when use approaches 128mb (get this value with memory_get_usage()
) divide the result into 2 or more arrays and return the result.
But how can I do that? Should I use a Buffer?
I’m already trying to use
fetchAll()
in place offetch()
? If no condition to increase$count
, use functioncount()
passing as argument the array offetchAll()
.– rray
The problem is not how I recover the data in the database but when storing the data in the variable:
$data[] = $row;
. It exceeds the memory size of PHP (128M), and I need to pass the data to another function before printing.– robertaodj