php.net |  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
 [2013-05-16 09:04 UTC] m4t1k at interia dot pl
Description:
------------
Regarding error #48343 from 2009, which still exists:
https://bugs.php.net/bug.php?id=48343&edit=2

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:
---------------
<?php

/**
    Mysql test table:

    CREATE TABLE `test` (
      `id` int(11) NOT NULL auto_increment,
      `value` int(11) NOT NULL,
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;


    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("127.0.0.1", "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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-07 10:08 UTC] uw@php.net
-Status: Open +Status: Not a bug -Package: mysqlnd_ms +Package: mysql
 [2013-06-07 10:08 UTC] uw@php.net
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 http://www.php.net/support.php 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: Tue Nov 30 13:03:49 2021 UTC