Bug #77554 [Opn->Dup]: memory leak while fetching
| From: | nikic@php.net | Date: | Fri, 01 Feb 2019 09:05:18 +0000 |
| Subject: | Bug #77554 [Opn->Dup]: memory leak while fetching | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-219318@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77554&edit=1
ID: 77554
Updated by: nikic@php.net
Reported by: 13dagger at gmail dot com
Summary: memory leak while fetching
-Status: Open
+Status: Duplicate
Type: Bug
Package: PDO MySQL
Operating System: archlinux
PHP Version: 7.3.1
Block user comment: N
Private report: N
New Comment:
This is the same issue as bug #77308, which will be fixed in the upcoming PHP 7.3.2 release.
Previous Comments:
------------------------------------------------------------------------
[2019-02-01 08:48:01] 13dagger at gmail dot com
Description:
------------
Problem happens if I request big table or table with lots of data in rows.
Memory usage increasing drastically while fetching one row at a time.
If I query only one field, ex id, memory usage grows slower.
The code in example gives "PHP Fatal error: Allowed memory size" after fetching ~175
rows.
Test example generates table, fill it and tries to fetch data row by row.
Tested the code in php 7.2 and it worked as expected.
Test script:
---------------
<?php
$db_name = '';
$db_user = '';
$db_pass = '';
ini_set('memory_limit', '10M');
$cn = 0;
$pdo = new \PDO('mysql:host=localhost;dbname=' . $db_name, $db_user, $db_pass);
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
$pdo->exec('DROP TABLE IF EXISTS test_mem_leak');
$pdo->exec('CREATE TABLE IF NOT EXISTS test_mem_leak (id INT AUTO_INCREMENT, txt TEXT,
PRIMARY KEY(id))');
$fill = str_repeat('test-', 10000);
for ($i = 0; $i < 500; ++$i) {
$pdo->exec("INSERT INTO test_mem_leak SET txt = '$fill'");
}
$q = $pdo->query('select * from test_mem_leak');
while ($d = $q->fetch()) {
echo $cn . ' ' . round(memory_get_usage() / (1024 * 1024), 3) . "MB \n";
++$cn;
}
echo "ok: $cn\n";
Actual result:
--------------
PHP Fatal error: Allowed memory size of 10485760 bytes exhausted (tried to allocate 53248 bytes) in
/home/me/code/tmp/1.php on line 16
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77554&edit=1