-1
I’m trying to display data in a table
through a foreach
in the php
of more than 17,000 database records, but shows HTTP ERROR 500
in the browser.
<?php foreach($dados as $dado):?>
<tr>
... // aqui vai os registros
</tr>
<?php endforeach;?>
The interesting thing is that when I limit the amount of records to display, for example 5 thousand, the error does not occur.
Would that be a memory problem of php
?
Maybe I shouldn’t use the foreach
?
Edit:
Apache log:
[Fri Sep 21 10:06:00 2018] [error] [client 192.168.0.100] PHP Fatal error:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 27316224
bytes) in Unknown on line 0, referer:
http://192.168.0.100/index.php/relatorio/
You need to look at the apache error log.
– rray
thanks for the tip.. really set the memory limit. I should increase or treat this in php?
– SM_S
As for the negative seems a bit exaggerated, use the [Edit] link and add the log error message. The way it is, you can’t tell where the problem is.
– rray
The ideal would be not to bring all the records.
– rray
I edited with the log. Maybe breaking in parts sql and bringing gradually
– SM_S
The solution will be to paginate the data even, there is not much to do. The question is: do you really need 17 thousand records on the same page? This seems to be unnecessary. Up to 5 thousand seems to be too.
– Woss
Yes, it’s a report and if I use paging, the excel plugin doesn’t work. Is there any way to clear the memory in each loop iteration?
– SM_S
A: You don’t need to create one array with all bank records. apparently you have in
$dados
all records, but usually the database driver implements a pointer scheme between records, making it possible to have only one record in memory at a time. Two: if PHP is generating an HTML code from the records, with 17,000 records the HTML will be gigantic, but you can facilitate the life of your server by releasing the output buffer with each iteration.– Woss