|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64855 memory leak on fetch array
Submitted: 2013-05-16 09:04 UTC Modified: 2013-06-07 10:08 UTC
From: m4t1k at interia dot pl Assigned:
Status: Not a bug Package: mysql (PECL)
PHP Version: 5.4.15 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: m4t1k at interia dot pl
New email:
PHP Version: OS:


 [2013-05-16 09:04 UTC] m4t1k at interia dot pl
Regarding error #48343 from 2009, which still exists:

There is a memory leak in mysqlnd (PHP 5.4.4-14 Debian Wheezy).
Switching between libmysql and mysqlnd shows that it is mysqlnd problem.

Every fetch row (mysql_fetch_row or pdo->fetch) in loop extends used memory and leads to out of memory fatal error in the end.

Test script:

    Mysql test table:

    CREATE TABLE `test` (
      `id` int(11) NOT NULL auto_increment,
      `value` int(11) NOT NULL,
      PRIMARY KEY  (`id`)

    INSERT INTO `test` VALUES (1, 910044366),(2, 598209383),(3, 1057704306),(4, 877739287),(5, 260395243),(6, 1154353180),(7, 19390630),(8, 362285832),(9, 510459913),(10, 222644712),(11, 824641253),(12, 969677378),(13, 1131665776),(14, 263701992),(15, 409107462);

$before = memory_get_usage();
echo "Memory Usage (in bytes)";
echo "\nBefore: " . $before;

$db = new mysqli("", "test", "testpasswd", "test");
$result = $db->query('SELECT * FROM `test`');

$rows = 0;
while($result->fetch_array(MYSQLI_ASSOC)) {$rows++;}

$after = memory_get_usage();
echo "\nAfter: " . $after;

echo "\nDelta: " . ($after - $before);
echo "\nDelta per row: " . round(($after - $before)/$rows) . ' bytes per row';

Expected result:
Memory Usage (in bytes)
Before: 55216
After: 56080
Delta: 864
Delta per row: 58 bytes per row

Actual result:
Memory Usage (in bytes)
Before: 321328
After: 337384
Delta: 16056
Delta per row: 1070 bytes per row

Would expect the Delta per row to be the similar for PHP 5.3 but this is 
no where near.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-07 10:08 UTC]
-Status: Open +Status: Not a bug -Package: mysqlnd_ms +Package: mysql
 [2013-06-07 10:08 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

See original bug report.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Dec 05 15:03:33 2021 UTC