|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-13 18:19 UTC] spheroid@php.net
Description:
------------
As stated on the summary, PDO DBLIB driver wont free memory
allocated to statements (or the resultset, not sure). Same
code done with ext/mssql functions works, though.
Reproduce code:
---------------
$db = new PDO('dblib:host=hostname;dbname=database', 'user', 'password');
$query = 'SELECT GETDATE()'; // NOW() on mysql
for ($i = 0; $i < 10; $i++) {
$stmt = $db->query($query); // new statement
$stmt->fetch(); // actual data
$stmt->fetch(); // false; end of resultset
$stmt->closeCursor(); // this should at least free it, right?
$stmt = null; // being paranoid here
echo memory_get_usage() . "\n";
}
Expected result:
----------------
54152
54152
54152
54152
54152
54152
54152
54152
54152
54152
Actual result:
--------------
54152
54252
54292
54332
54372
54412
54452
54492
54532
54572
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 00:00:02 2025 UTC |
I couldn't get it to compile, so I corrected the mysql -> dblib, not sure whether this was the intention though. I don't have enough karma, so the patch is below: RCS file: /repository/php-src/ext/pdo_dblib/dblib_stmt.c,v retrieving revision 1.6.2.2.2.3 diff -u -r1.6.2.2.2.3 dblib_stmt.c --- dblib_stmt.c 14 Jan 2007 16:57:50 -0000 1.6.2.2.2.3 +++ dblib_stmt.c 14 Jan 2007 21:43:35 -0000 @@ -250,9 +250,9 @@ return 1; } -static int dblib_mysql_stmt_cursor_closer(pdo_stmt_t *stmt TSRMLS_DC) +static int pdo_dblib_stmt_cursor_closer(pdo_stmt_t *stmt TSRMLS_DC) { - pdo_dblib_stmt *S = (pdo_mysql_stmt*)stmt- >driver_data; + pdo_dblib_stmt *S = (pdo_dblib_stmt*)stmt- >driver_data; if (S->rows) { free_rows(S TSRMLS_CC); @@ -273,6 +273,6 @@ NULL, /* get attr */ NULL, /* meta */ NULL, /* nextrow */ - dblib_mysql_stmt_cursor_closer + pdo_dblib_stmt_cursor_closer }; However, it doesn't fix the problem. See, gdb breaks fine on pdo_dblib_stmt_dtor on each iteration and stepping it shows that it even attempts to free stuff. So I guess the error isn't here? After running gdb with patch above it does close the cursor on each iteration, but it's not still affecting the increasing memory usage.And more issues :-) That previous example was done with just one row in the resultset, but after I tried to return more rows, I found something disturbing: Code: $db = new PDO('dblib:host=hostname;dbname=database', 'username', 'password'); $query = 'select top 10 * from table'; $stmt = $db->prepare($query); for ($i = 0; $i < 10; $i++) { $stmt->execute(); $stmt->fetchAll(); $stmt->closeCursor(); echo memory_get_usage() . "\n"; } Output: 172240 240044 307824 375632 443464 511288 579064 646932 714776 782576