Bug #67898 [Opn->Csd]: Memory allocation problem - memory not freed
| From: | tomas at slax dot org | Date: | Tue, 28 Oct 2014 12:34:06 +0000 |
| Subject: | Bug #67898 [Opn->Csd]: Memory allocation problem - memory not freed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188340@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67898&edit=1
ID: 67898
User updated by: tomas at slax dot org
Reported by: tomas at slax dot org
Summary: Memory allocation problem - memory not freed
-Status: Open
+Status: Closed
Type: Bug
Package: MySQL related
Operating System: Slackware Linux
PHP Version: 5.5.16
Block user comment: N
Private report: N
New Comment:
I'm going to close this since I've identified the problem and I'll open a new bug for
that.
Previous Comments:
------------------------------------------------------------------------
[2014-10-26 23:17:07] php at mcq8 dot be
Please note that the memory is freed when the mysql_query variable gets destroyed.
If you would loop over the mysqli_query part, you would see that the memory is freed.
Furthermore, the amount of memory used when all records have been fetched is approximately the same
as not using the mysqlnd so you it is just an optimization or hidden from the memory usage as
johannes said
------------------------------------------------------------------------
[2014-09-01 19:22:16] tomas at slax dot org
Test it yourself, with this simple script:
<?php
echo "connecting to database...\n";
$link=mysqli_connect("localhost",'root','','test');
echo "creating table with lots of rows...\n";
mysqli_query($link,"CREATE TEMPORARY TABLE tbl123 LIKE mysql.user");
for ($i=0;$i<6000; $i++)
{
mysqli_query($link,"INSERT IGNORE INTO tbl123 SET
host='x".$i."'");
}
echo "getting all rows from database\n";
$result=mysqli_query($link,"SELECT * FROM tbl123");
while($row=mysqli_fetch_row($result))
{
echo "Mem used:
".number_format(memory_get_usage()/1024,1,'.','')." KB\n";
}
// expected result: memory usage still the same
// Actual result: memory usage increases with each row :(
?>
------------------------------------------------------------------------
[2014-09-01 17:58:58] tomas at slax dot org
Thank you for your reply.
I'm not sure what difference are you mentioning.
There is NO DIFFERENCE AT ALL.
The memory problem is there for both, mysql_* and mysqli_* functions. It's the same.
------------------------------------------------------------------------
[2014-09-01 14:49:36] johannes@php.net
mind that
1) mysql_* APIs are deprecated and should not be used,
2) mysql_query is buffering the result set so it's all in memory and
3) your difference comes from using libmysql vs mysqlnd as client library, mysqlnd uses PHP memory
and therefore PHP reports more accurate memory usage, with libmysql memory used inside the library
is hidden
------------------------------------------------------------------------
[2014-08-29 20:45:32] tomas at slax dot org
I was unable to get the mentioned memory error with Debian's PHP 5.4.4-14+deb7u14 (tested only
with the CLI binary). The memory is properly freed there. However when I took the sources + patches
from debian, and compiled on the very same debian box, the memory issue is there again. I tried with
simple ./configure --with-mysql --with-mysqli, the compiled binary has the problem with memory which
is not freed.
This is very odd. If anybody helps me to replicate Debian's compilation then I could maybe
track down what option is responsible...
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=67898
--
Edit this bug report at https://bugs.php.net/bug.php?id=67898&edit=1