Edit report at http://bugs.php.net/bug.php?id=51796&edit=1
ID: 51796
User updated by: J dot Antonio at jaruz dot com
Reported by: J dot Antonio at jaruz dot com
Summary: Memory leak when executing SQL "EXEC" statements
Status: Open
Type: Bug
Package: PDO related
Operating System: Ubuntu 10.04 LTS
PHP Version: 5.3.2
New Comment:
I forgot to mention this is using PDO_DBLIB.
Previous Comments:
------------------------------------------------------------------------
[2010-05-11 17:48:35] J dot Antonio at jaruz dot com
Description:
------------
On Linux, using PHP 5.3.2-1ubuntu4 with Suhosin-Patch (cli) and FreeTDS
0.82-6build1 (it's a vanilla lucid install, fully up to date):
When executing stored procedures using the "EXEC" SQL statement, both
PDOStatement->execute as well as PDO::query seem to have a memory leak.
We found this while executing a stored procedure within a loop: memory
usage just kept increasing till the memory limit was reached.
Unsetting/nullyfing variables does not help.
The leak is not present (memory usage stays perfectly constant) when
using a "SELECT" SQL statement (which returns the exact same results as
the stored procedure).
I have a feeling PDO is maybe only clearing the memory when it deals
with a "SELECT" statement, and it misses the fact that data can also
come back through "EXEC" statements?
This bug might be slightly related to bug 50755.
Test script:
---------------
// $polyItemArray is populated with a list of 300 IDs (integers).
// We loop through the array, and execute a stored procedure during each
iteration:
foreach( $polyItemArray as $polyItemKey => $polyItem) {
echo date('H:i:s') . ' | Processing: ' . $polyItem['sgp_id'];
$dbh->query('EXEC proc_map_get_sgp_polygons ' . $polyItem['sgp_id'],
PDO::FETCH_ASSOC);
/*
// Alternate way of calling the procedure using PDOStatement;
same leak is present:
$stmt = $dbh->prepare($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$stmt->execute( array($polyItem['sgp_id']) );
$stmt->closeCursor();
unset($stmt);
*/
unset($polyItemKey);
unset($polyItem);
echo ' memory usage: ' . memory_get_usage(). ' bytes'. PHP_EOL;
}
// When running the script, memory usage just keeps increasing.
Expected result:
----------------
I would expect the memory usage of the script to stay constant.
Actual result:
--------------
Memory usage just keeps increasing.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51796&edit=1