ID: 48343
Comment by: ninzya at inbox dot lv
Reported By: mikec at mikenz dot geek dot nz
Status: Open
Bug Type: MySQLi related
Operating System: *
PHP Version: 5.3CVS-2009-05-20 (snap)
New Comment:
Try destroying mysqli object before calculating estimated memory usage.
See what are results.
Previous Comments:
------------------------------------------------------------------------
[2009-05-20 05:56:05] mikec at mikenz dot geek dot nz
Description:
------------
A simple loop fetching rows from a database uses a lot more memory of
php5.3 when compared to php5.2.
First noticed on a Debian machine. Confirmed on a Windows machine with
latest snaps (20-May-2009). php.ini based on php.ini-dist/development
only change is to enable mysqli.
Reproduce code:
---------------
<?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:
----------------
C:\test\php-5.2-nts-win32-VC6-x86-latest>php -v
PHP 5.2.10-dev (cli) (built: May 19 2009 11:46:39)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
C:\test\php-5.2-nts-win32-VC6-x86-latest>php r:\dbmem.php
Memory Usage (in bytes)
Before: 55216
After: 56080
Delta: 864
Delta per row: 58 bytes per row
Actual result:
--------------
C:\test\php-5.3-nts-win32-VC9-x86-latest>php -v
PHP 5.3.0RC3-dev (cli) (built: May 19 2009 12:57:00)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
C:\test\php-5.3-nts-win32-VC9-x86-latest>php r:\dbmem.php
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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48343&edit=1