Doc #61060 [ReO->Csd]: MySQL memory leak
| From: | philip@php.net | Date: | Fri, 01 Jun 2012 06:48:35 +0000 |
| Subject: | Doc #61060 [ReO->Csd]: MySQL memory leak | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-8411@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61060&edit=1
ID: 61060
Updated by: philip@php.net
Reported by: trusty_jim at hotmail dot com
Summary: MySQL memory leak
-Status: Re-Opened
+Status: Closed
Type: Documentation Problem
Package: MySQL related
Operating System: Windows Vista
PHP Version: 5.3.10
Assigned To: philip
Block user comment: N
Private report: N
New Comment:
This is now documented, thank you for the report.
Previous Comments:
------------------------------------------------------------------------
[2012-04-18 21:19:49] philip@php.net
Automatic comment from SVN on behalf of philip
Revision: http://svn.php.net/viewvc/?view=revision&revision=325320
Log: Added concepts section for MySQL docs. And added basic info about buffered vs unbuffered.
Incomplete but should be helpful for discussion and/or lure others into adding content. :) That part
deals with PHP Bug #61060
------------------------------------------------------------------------
[2012-04-18 21:03:06] philip@php.net
Automatic comment from SVN on behalf of philip
Revision: http://svn.php.net/viewvc/?view=revision&revision=325318
Log: Partially document PHP bug #61060, with more to come. Help clarify memory memory reporting with
mysqlnd vs libmysql
------------------------------------------------------------------------
[2012-04-18 20:56:23] philip@php.net
Marking as a doc bug, as suggested by Rasmus. Assigning to self.
------------------------------------------------------------------------
[2012-04-11 14:35:21] rasmus@php.net
This will depend on your mysql client library, and it isn't actually a memory
leak.
Running your script on my Ubuntu box gives me:
Start Memory : 227784
228240
228240
228240
228240
228240
228240
228240
228240
228240
228240
End Memory : 228120
On both PHP 5.3.11 and PHP 5.4.1 using the old outdated mysql extension built
against libmysqlclient-dev-5.1.61-0ubuntu0.11.10.1
Now, if however you are using the mysqlnd library, keep in mind that this
library uses PHP native memory management system, so anything allocated by the
library shows up in memory_get_usage(). So, using mysqli linked against mysqlnd
I get:
Start Memory : 235440
9969808
9970720
9971632
9972544
9973456
9974368
9975280
9976192
9977104
9978016
End Memory : 295280
But this makes perfect sense. Each time you fetch a row from the MySQL server
the client library needs to allocate memory to store that row. This happens in
the non-mysqlnd case as well, but it uses a straight system malloc() call so the
memory doesn't show up when you call memory_get_usage(). It is still eating
memory, and it isn't actually a leak, that's how the library works. You get your
memory back when you free the result.
Now, what this bug report is really asking is how do we tell the client library
not to buffer rows as we read them from the server. That's what unbuffered
queries are all about. In mysqli this see the use_result() method. For the old
deprecated mysql extension, see the mysql_unbuffered_query() function.
So, this is not actually a bug.
------------------------------------------------------------------------
[2012-04-10 16:59:23] jim at bladehq dot com
I have experienced this issue too. It appears to only leak memory when the query is SELECT *. This
has caused our application to run out of memory when iterating over large result sets.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=61060
--
Edit this bug report at https://bugs.php.net/bug.php?id=61060&edit=1