Bug #65741 [Opn->Nab]: High memory usage from mysqli:query()
| From: | rasmus@php.net | Date: | Mon, 23 Sep 2013 14:29:55 +0000 |
| Subject: | Bug #65741 [Opn->Nab]: High memory usage from mysqli:query() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181752@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65741&edit=1
ID: 65741
Updated by: rasmus@php.net
Reported by: cduncan at regatta dot com
Summary: High memory usage from mysqli:query()
-Status: Open
+Status: Not a bug
Type: Bug
Package: MySQLi related
Operating System: Linux
PHP Version: 5.5.4
Block user comment: N
Private report: N
New Comment:
The "appears to use" is key here. I bet you are using the mysqlnd driver now
which means that the mysql library is using the PHP memory allocator which in
turn means that memory_get_usage() is now able to see and track that memory.
Before, using libmysqlclient, you were using just as much memory, but
memory_get_usage() just couldn't see it. In fact, you were using more because it
would get malloc'ed once by libmysqlclient and then when you fetched rows from
PHP it would get copied to PHP-controlled memory. Now with the native driver that
copy is no longer needed.
Previous Comments:
------------------------------------------------------------------------
[2013-09-23 13:03:43] cduncan at regatta dot com
Description:
------------
When executing a query that returns a large number of rows (around 16 million) the query() function
appears to use a lot more memory than it did in version 5.3.8
I looked through the changelogs and couldn't find any obvious reason why, or any mention of a
change in how the function works
Test script:
---------------
<?php
$sql = new mysqli("localhost","username","password");
function checkMemory($key="") {
$memory = round(memory_get_usage(true) / 1024 / 1024) . "mb";
echo "Memory " . $key . ": " . $memory . "\n";
}
checkMemory("Before");
$query = "SELECT field1a, field2a, valb1, valb2, valb3, valb4 FROM test.table1
JOIN test.table2 ON companyb=companya AND field1b=field1a
WHERE companya='TEST'";
$result = $sql->query($query);
checkMemory("After");
$field = $result->fetch_field();
echo "End\n";
Expected result:
----------------
user@server:~$ /usr/local/php-5.3.8/bin/php memory.php
Memory Before: 1mb
Memory After: 1mb
End
Actual result:
--------------
user@server:~$ /usr/local/php-5.5.4/bin/php memory.php
Memory Before: 0mb
Memory After: 427mb
PHP Fatal error: Out of memory (allocated 1603796992) (tried to allocate 20 bytes) in
/home/user/memory.php on line 17
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65741&edit=1