php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77599 Unbuffered queries; native prepared statements memory leak
Submitted: 2019-02-11 03:23 UTC Modified: 2019-02-11 09:38 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: dylan at php dot waywardrambler dot com Assigned: dmitry (profile)
Status: Closed Package: PDO MySQL
PHP Version: 7.3.2 OS: MacOS 10.14.3
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dylan at php dot waywardrambler dot com
New email:
PHP Version: OS:

 

 [2019-02-11 03:23 UTC] dylan at php dot waywardrambler dot com
Description:
------------
Memory leak when running unbuffered queries in PDO with ATTR_EMULATE_PREPARES set to false.

Test script:
---------------
<?php
ini_set('memory_limit', '16M');

$pdo = new PDO('mysql:host=*;dbname=*', '*', '*');
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

$result = $pdo->query("SELECT * FROM large_table");

foreach ($result as $i => $row)
    if ($i % 10000 === 0)
        printf("%10s %10s\n", $i, memory_get_usage());

Expected result:
----------------
consistent memory usage, eg:

         0     2097152
     10000     2097152
     20000     2097152
     30000     2097152
     40000     2097152

Actual result:
--------------
         0    2097152
     10000    4194304
     20000    8388608
     30000    12582912
     40000    14680064

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16384 bytes) in /php on line 10

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-11 08:19 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2019-02-11 08:19 UTC] nikic@php.net
Are you sure that you're really using PHP 7.3.2 and not PHP 7.3.1? This bug is supposed to be fixed.
 [2019-02-11 09:23 UTC] dylan at php dot waywardrambler dot com
-Status: Feedback +Status: Open
 [2019-02-11 09:23 UTC] dylan at php dot waywardrambler dot com
Fairly sure "PHP 7.3.2 (cli) (built: Feb  5 2019 22:19:09) ( NTS )".

I have also checked on the official 7.3.2-cli container and the issue is still present.
 [2019-02-11 09:38 UTC] nikic@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: dmitry
 [2019-02-11 09:38 UTC] nikic@php.net
You're right. It looks like unbuffered queries + emulated prepares no longer leask, but unbuffered queries + native prepares still leaks.
 [2019-02-12 08:04 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b6e58dcd2262c30c0657624ca3c372dc90d5a031
Log: Fixed bug #77599 (Unbuffered queries; native prepared statements memory leak)
 [2019-02-12 08:04 UTC] dmitry@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC