6
In PHP I often work a lot with frameworks. Generally, they bring the results of the query to a database in a array
.
In some cases, when the number of data from a table or a relationship reaches a very large level, if we don’t use resources like paging or an ajax Lazy load, that error may happen.
Fatal error: Allowed memory size of 99999999 bytes exhausted
I’ve heard cases that, with me, too big an array generated this error, but this can vary from a php.ini configuration (memory_limit
) to another. However, there is usually a default value for the memory limit - which in the case is 128M for versions equal to or higher than PHP 5.3.
Taking into account the pre-definition of 128M
, it would be possible to arrive at a calculation, to know more or less, what is the amount of data that we could use in a array
?
There is a recommended maximum size for me to allocate values in one array
?
Wallace if an array reaches that amount something is very wrong in your code ;)
– Jorge B.
@Jorgeb. Yes, of course. Only with the
Codeigniter
to date, rsrsrsrs.– Wallace Maxters
@Jorgeb. not always. It can be an input changed by the console and create something like:
<input name="q[][][]" type="text" />
, and input N indices by changing the attributename
with hundreds of[]
.– Papa Charlie
It’s up to the developer to work the data, I know, but it’s just one example that an array can be from an external source. By default abolishes array of forms, including checkbox’s.
– Papa Charlie
@Papacharlie and, because it is an external form, you can "inject" a giant array to generate an error. I’ve already done it, with a suicide form.
– Wallace Maxters
@Papacharlie but here we are talking about arrays from the database, at least that’s what I understood.
– Jorge B.
@Jorgeb. array from the database was just an example. Actually, I did, because it’s one of the ways that it’s easier for you to generate an error from memory exhaustion. Other array sources are "accepted for the answer," but I can’t think of one that could impact as much as the database.
– Wallace Maxters
@Jorgeb, it was just an addendum
– Papa Charlie
@Wallacemaxters, I’ve also manipulated mine in test environment and so I abolished array in form.
– Papa Charlie
@Papacharlie but it doesn’t do much good. The guy who edit your form, can add a
array
there. I already managed to bug a system of a guy like ;0– Wallace Maxters
@Wallacemaxters, your victim was probably wearing something like
htmlspecialchars
direct with the value of$_POST
. In my case if the value is an array I do a casting for null value.– Papa Charlie