From:             [EMAIL PROTECTED]
Operating system: Debian sid (linux kernel 2.6.0)
PHP version:      5.0.0b3 (beta3)
PHP Bug Type:     Scripting Engine problem
Bug description:  Possible memory leak in variable interpolation

Description:
------------
I'm using a php script for a large (batch) process (about 4 hours
procesing DB data) and I found the script grows and grows in memory usage.
I've searched and simplify the script to see where was the problem and I
found that a simple php script is loosing memory when interpolating
variables in a string. I don't know if this is exactly a bug or an
expected behavior, but I found it weird and very problematic on large
scripts.

I'm using Debian GNU/Linux sid with kernel 2.6.0. I've tested the
reproduce code in PHP 5.0.0beta3 compiled by myself[1] and with Debian's
PHP 4.3.3 package in the cli and apache module interfaces.

[1] PHP 5.0.0beta3 was compiled with this flags:
'./configure' '--prefix=/usr/local/stow/php5' '--enable-memory-limit'
'--with-openssl' '--with-zlib' '--enable-bcmath--with-bz2'
'--enable-calendar' '--with-curl' '--enable-dba' '--with-db4'
'--with-flatfile' '--with-inifile' '--enable-dbase' '--enable-dbx'
'--enable-dio' '--enable-exif' '--enable-filepro' '--enable-ftp'
'--with-gd' '--with-gettext' '--with-iconv' '--with-mime-magic'
'--with-mysql' '--with-ncurses' '--enable-pcntl' '--with-readline'
'--enable-sockets' '--with-sqlite' '--enable-sysvmsg' '--enable-sysvsem'
'--enable-sysvshm' '--enable-wddx' '--enable-yp'
'--with-apxs2=/usr/bin/apxs2'
using gcc 3.3.3 (debian package)

Reproduce code:
---------------
<?php
for ($i = 0; $i < 260; $i++)
    echo("Memory usage ($i): ".memory_get_usage()."\n");
?>


Expected result:
----------------
Memory usage (<i>): <mem>

where <i> is the iteration step and <mem> is a constant ammount of memory
used by the script. For example:

Memory usage (0): 32224
Memory usage (1): 32224
[snip]
Memory usage (258): 32224
Memory usage (259): 32224


Actual result:
--------------
Memory usage (0): 32224
Memory usage (1): 32272
Memory usage (2): 32296
Memory usage (3): 32320
[snip]
Memory usage (251): 38272
Memory usage (252): 38296
Memory usage (253): 38320
Memory usage (254): 38344
Memory usage (255): 38344
Memory usage (256): 38344
Memory usage (257): 38344
Memory usage (258): 38344
Memory usage (259): 38344

>From 254 and up, the ammount of memory used stays constant (excepting when
the loop is about 1000000 long, in that case the memory consumption raises
a little but then stays constant again).

If I don't use variable interpolation and use the concatenation operator
(.), like this:
echo("Memory usage (".$i."): ".memory_get_usage()."\n");
more memory is used in the second iteration but then stays constant:
Memory usage (0): 31880
Memory usage (1): 31928
Memory usage (2): 31928
Memory usage (3): 31928
Memory usage (4): 31928
[snip]

-- 
Edit bug report at http://bugs.php.net/?id=26982&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=26982&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=26982&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=26982&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=26982&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=26982&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=26982&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=26982&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=26982&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=26982&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=26982&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=26982&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=26982&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26982&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=26982&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=26982&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=26982&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26982&r=float

Reply via email to