Nikolai Chuvakhin wrote:
for ($i=0;$i<100000 ;$i) {
$sql = "select id from table where id=x";
$db->query($sql);
}
if i run this code memory usage grow up, during for loop
but if i use mysql_query($sq l) instead of $db->query($sql), memory
usage stay the same during all for loop
This is a rather well-known deficiency in memory management in PHP 4.
Memory allocated to objects is not released until the end of script's
execution.
To be more accurate, PHP4 releases memory taken by objects created from
simple user classes before the script ends - i.e. when variable is no
longer used or it is being assigned a new value. But it doesn't work the
same way when you have an object from a more complex class structure.
Exactly what causes it - I don't know.
Have you an idea to solve my problem ?
Don't use OOP in general and database abstraction layers in particular.
Another option is to switch to PHP 5, where this problem has purportedly
been solved.
Yes, at least with what I have tested, memory usage still starts to grow,
but levels out at some point. In my testing, it's definitely not nearly as
efficient as using variables and functions.
Even if OP were to switch to and run the script in PHP5, it would be a good
idea to first try the script both ways (with and without objects in the for
loop) and track the memory usage during that for loop to help him decide if
using objects is right for him.