ID:               48528
 Updated by:       u...@php.net
 Reported By:      bugs dot php dot net at moesen dot nu
-Status:           No Feedback
+Status:           Closed
 Bug Type:         MySQL related
 Operating System: Linux 2.6
 PHP Version:      5.3CVS-2009-06-11 (snap)
 New Comment:

Duplicate of http://bugs.php.net/bug.php?id=48343 - there is no leak,
mysqlnd and libmysql work differently. 


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

[2009-10-30 12:32:15] guenter at grodotzki dot ph

same problem here, though with the normal mysql_query + mysql_fetch*
functions

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

[2009-06-20 01:00:00] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

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

[2009-06-16 08:31:16] bugs dot php dot net at moesen dot nu

> libmysql's allocations are hidden.
OK, that explains the numbers. Thanks.

> Do you really get OOM with mysqlnd?
Yes, for the same dataset.

> as you can see the memory usage with USE_RESULT doesn't jump
Thanks for that pointer. I completely missed it in the documentation,
and since we never had any problems before switching over to 5.3, I
never needed it. The human equivalent of lazy evaluation, I guess.

So if I understand it correctly, libmysql is not subject to PHP's
memory limit, whereas mysqlnd is?

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

[2009-06-12 07:36:09] and...@php.net

Do you really get OOM with mysqlnd? memory_get_usage() is constant with
libmysql because libmysql allocates its memory with malloc while Zend
and all PHP functions mostly use emalloc. emalloc counts the allocated
memory. libmysql's allocations are hidden.
I tried your script, created a simple table with the same name and 
- int
- double
- varchar
- decimal
columns.
I have 33 rows. Here is the output when the data is fetched with
MYSQLI_STORE_RESULT, which is the default:
361756 <- before $result = $db->query
366384
366656
366928
367200
367472
367744
368016
368288
368560
368832
369104
369376
369648
369920
370192
370464
370736
371008
371280
371552
371824
372096
372368
372640
372912
373184
373456
373728
374000
374272
374544
374816
375088
362840 <- this is the result after I do $result->free_result(), which
means that the memory doesn't leak. Most of it is reclaimed. It can be
that Zend also cache some zvals in its zval cache, which means that
memory has not leaked and is there for further usage. 

Here is with MYSQLI_USE_RESULT:
361756  <- before $result = $db->query
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
365764
362840 <- After $result->free_result()

So, as you can see the memory usage with USE_RESULT doesn't jump, for a
reaon. Because data is not stored on the client side. With libmysql you
cannot see it, but the usage is there.



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

[2009-06-11 12:17:57] bugs dot php dot net at moesen dot nu

Description:
------------
PHP 5.3 leaks memory when using the MySQL functions, both through PDO
and MySQLi directly. When recompiled without mysqlnd, the same code
works fine.

./configure --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd
--with-pdo-mysql=shared,mysqlnd [ . . . ]

Recompiled today's snapshot without the ',mysqlnd'.

Reproduce code:
---------------
PDO:
$db = new PDO($dsn, $user, $pass);
$stmt = $test->prepare('SELECT * FROM
tech_eciffOkcab.crawlPriceComp');
$result = $stmt->execute();
while($result && $row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        echo memory_get_usage(), "\n";
}

MySQLi:
$db = new MySQLi($host, $user, $pass);
$result = $db->query('SELECT * FROM tech_eciffOkcab.crawlPriceComp');
while ($result && $row = $result->fetch_assoc()) {
        echo memory_get_usage(), "\n";
}


Expected result:
----------------
Consistent memory_get_usage();

I.e., no extra memory required, and thus no out-of-memory errors.

Actual result:
--------------
Linearly increasing memory_get_usage();

PDO:
23168400
23169064
...
33552804
33552916
-> OOM and segfault.

MySQLi:
23168216
23168700
...
33552812
33552924
-> OOM and segfault.


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


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

Reply via email to