ID:               32829
 Updated by:       [EMAIL PROTECTED]
 Reported By:      fransson at fransson dot de
-Status:           Open
+Status:           Feedback
 Bug Type:         Performance problem
 Operating System: Windows XP
 PHP Version:      4.3.11
 New Comment:

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.




Previous Comments:
------------------------------------------------------------------------

[2005-04-26 02:07:04] fransson at fransson dot de

Description:
------------
PHP runs out of memory when iterating large loops. It seems that it
does not free unused memory. The Windows Task Manager indicates that it
tries to allocate more than 2 Gigabytes of memory (on my P4 with 1
Gigabyte) before crashing with an access violation.

In my opinion this is a performance problem in the first place.  The
crash does help in this case because the machine becomes usable again.

Although I guess it is not, this problem might be related to the MySQL
interface because the loops which are causing my troubles are of the
following structure:

while ($row = mysql_fetch_array($set, MYSQL_ASSOC)) {
  ...
}

I guess that the data being stored in the variable $row with each
iteration is never being freed up by php, although it can never be
referenced again after the next iteration has overwritten the old
reference.

To be more explicit:
1. Before the execution of the while-loop, $row does not even exist and
therefore does not consume any memory.
2. During the execution of the first iteration of the while-loop, $row
consumes only enough memory to hold a single row of the result set
(which might be around 20 KB in my case).
3. During the execution of the second iteration, $row is being
overwritten with a new row of the result set. Its previous value is not
accessible any more, but nevertheless consumes memory. Therefore,
assuming a memory consumption of about 20 KB per row, the total memory
consumption during the second iteration is 40 KB. 20 KB of these are
completely wasted since they remain inaccessible to the application.
4. The larger the result set, the larger the memory wasted. If it is
large enough, it will slow down and crash any machine. In my case, the
result set holds about 50,000 records.




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32829&edit=1

Reply via email to