Bug #77554 [NEW]: memory leak while fetching
| From: | 13dagger at gmail dot com | Date: | Fri, 01 Feb 2019 08:48:01 +0000 |
| Subject: | Bug #77554 [NEW]: memory leak while fetching | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219317@lists.php.net to get a copy of this message | ||
From: 13dagger at gmail dot com
Operating system: archlinux
PHP version: 7.3.1
Package: PDO MySQL
Bug Type: Bug
Bug description:memory leak while fetching
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 bug report at https://bugs.php.net/bug.php?id=77554&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77554&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77554&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77554&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77554&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77554&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77554&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77554&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77554&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77554&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77554&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77554&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77554&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77554&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77554&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77554&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77554&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77554&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77554&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77554&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77554&r=mysqlcfg