|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71469 mysqli_fetch_field increases memory usage by large amount
Submitted: 2016-01-28 00:22 UTC Modified: 2017-05-10 10:05 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:-1 (-100.0%)
From: ryan dot brothers at gmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.6.17 OS: Linux
Private report: No CVE-ID: None
 [2016-01-28 00:22 UTC] ryan dot brothers at gmail dot com
I am seeing an issue in PHP 5.6.17 where after running a large database query, calling mysqli_fetch_field increases memory usage by a large amount.  The same issue occurs in PHP 7.0.2.

In the below example, the call to fetch_field increases the memory usage from 1.8MB to 6.6MB.

I have placed SQL to create a test table of 100,000 rows at

Is this expected behavior or an issue with memory usage?

Thanks for your help.

Test script:
$mysqli = new mysqli('localhost', 'test', 'test', 'test');

$mysqli->real_query("SELECT * FROM a");

$result = $mysqli->store_result();

echo 'a: '.memory_get_usage()."\n";

$field = $result->fetch_field();

echo 'b: '.memory_get_usage()."\n";

Expected result:
a: 1833136
b: 1833136 (or close to it)

Actual result:
a: 1833136
b: 6635728


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-10 10:05 UTC]
-Status: Open +Status: Not a bug
 [2017-05-10 10:05 UTC]
Yes, that is expected.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 18 21:03:39 2021 UTC