php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77554 memory leak while fetching
Submitted: 2019-02-01 08:48 UTC Modified: 2019-02-01 09:05 UTC
From: 13dagger at gmail dot com Assigned:
Status: Duplicate Package: PDO MySQL
PHP Version: 7.3.1 OS: archlinux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 13dagger at gmail dot com
New email:
PHP Version: OS:

 

 [2019-02-01 08:48 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-01 09:05 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2019-02-01 09:05 UTC] nikic@php.net
This is the same issue as bug #77308, which will be fixed in the upcoming PHP 7.3.2 release.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC