Bug #67898 [Opn]: Memory allocation problem - memory not freed

From: Date: Mon, 01 Sep 2014 14:49:37 +0000
Subject: Bug #67898 [Opn]: Memory allocation problem - memory not freed
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187366@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 Updated by: johannes@php.net Reported by: tomas at slax dot org Summary: Memory allocation problem - memory not freed Status: Open Type: Bug Package: MySQL related Operating System: Slackware Linux PHP Version: 5.5.16 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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... ------------------------------------------------------------------------ [2014-08-24 18:59:36] tomas at slax dot org I was able to confirm that the bug is not there in PHP 5.3.29. So it was introduced in 5.4.x .. oh my god this is serious, so many years ... I am unable to find sources for PHP 5.4.0 for test. Ideas? ------------------------------------------------------------------------ [2014-08-24 17:57:35] tomas at slax dot org The same issue can be observed on PHP 5.4.20. The same issue can be reproduces on PHP 5.6.0RC4 :( All compiled on Slackware Linux. ------------------------------------------------------------------------ [2014-08-24 11:53:34] tomas at slax dot org Description: ------------ If I simply get data from MySQL, PHP consumes more memory for every row: With some older PHP 5.3 versions, it prints constant number all the time, because RAM is properly freed. But with PHP 5.5.15 and 5.5.16 it prints increased amount of RAM for each row, as like the memory is not properly freed. If the mysql table has lots of rows, PHP script ends on trying to allocate more memory than allowed in php.ini The same problem appears when using mysql_fetch_row(). The same problem appears when using MySQLi extension instead of mysql. The same problem is there if using PHP on command line, the same problem when using PHP as Apache's module. I compile PHP from sources, using this configure script: CFLAGS="-O2 -fPIC" ./configure \ --libdir=/usr/lib64 \ --with-libdir=lib64 \ --disable-debug \ --disable-libxml --disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter \ --disable-dom \ --enable-mbstring --enable-mbregex \ --without-sqlite3 \ --without-pdo_sqlite \ --without-pear \ --with-mysql \ --with-mysqli \ --enable-ftp \ --with-iconv \ --with-zlib \ --with-png-dir=/usr \ --with-jpeg-dir=/usr \ --with-openssl \ --with-gd \ --with-freetype-dir=/usr \ --enable-gd-native-ttf \ --with-apxs2=/usr/bin/apxs \ --build=x86_64-slackware-linux Test script: --------------- $result=mysql_query("SELECT * FROM table"); while($row=mysql_fetch_assoc($result)) { echo memory_get_usage()."\n"; } Expected result: ---------------- I expect PHP to print constant number since it should not allocate more RAM. Like 501320 501320 501320 501320 501320 501320 501320 501320 ... Actual result: -------------- I get increased number of used RAM 56000376 56001384 56002392 56003400 56004408 56005416 56006424 56007432 56008440 56009448 56010456 56011464 56012472 56013480 56014488 56015496 56016504 56017512 56018520 56019528 56020536 56021544 56022552 56023560 56024568 56025576 56026584 56027592 56028600 56029608 ... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67898&edit=1

« previous php.bugs (#187366) next »