|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-06-11 07:04 UTC] i-devolder at jm-bruneau dot be
Description:
------------
When running a query the memoryusage keeps on rising, discovered with huge resultsets
Reproduce code:
---------------
$test = new PDO( $dsn , $usr , $pss );
$sql = "SELECT * FROM tech_eciffOkcab.crawlPriceComp";
$stmt = $test->prepare( $sql );
$stmt->execute();
while( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ) {
echo memory_get_usage()."\n";
}
Expected result:
----------------
57752
57752
57752
57752
57752
57752
57752
57752
57752
57752
output from php 5.2.9, memory usage stays the same
Actual result:
--------------
33552328
33552440
33552552
33552664
33552776
33552888
33553000
PHP Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 20 bytes) in /home/idev/web/private/cmdscripts/testmem.php on line 16
output from php 5.3RC2, memory usage keeps increasing ( this is on a table with 1.2 million records
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
This bug is _NOT_ bogus. A PHP developer should not have to care about malloc. Memory use increases when fetching, and there is no way in PHP to free it. I'm not sure how else to define a memory leak bug in a PHP extension. Here is another test case that doesn't require any tables: <? $host = ''; $db = ''; $usr = ''; $pwd = ''; $dsn = "mysql:host={$host}; dbname={$db}; username={$usr}; password={$pwd}"; print "PHP Version: " . PHP_VERSION . "\n\n"; function run_query($query) { global $dsn, $usr, $pwd; $pdo = new PDO($dsn, $usr, $pwd); $stmnt = $pdo->query($query); while (($stmnt->fetch(PDO::FETCH_ASSOC))) ; unset($pdo); unset($stmnt); } // This function demonstrates that the same query run twice will not increase memory usage, but new queries will. function test_query($query) { print "{$query}\n"; print "Before: " . memory_get_usage() . "\n"; run_query($query); print "Between: " . memory_get_usage() . "\n"; run_query($query); print "After: " . memory_get_usage() . "\n"; } test_query("SHOW VARIABLES;"); print "\n"; test_query("SHOW MASTER STATUS;"); ?> Results (Linux fresh compile): PHP Version: 5.3.0 SHOW VARIABLES; Before: 325980 Between: 326156 After: 326156 SHOW MASTER STATUS; Before: 326160 Between: 326160 After: 326160 Results (Windows Zend Core): PHP Version: 5.2.6 SHOW VARIABLES; Before: 75584 Between: 77640 After: 77640 SHOW MASTER STATUS; Before: 77672 Between: 77768 After: 77768