php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45644 eval() consumes a lot more memory in 64bit system than 32 bit
Submitted: 2008-07-28 12:18 UTC Modified: 2008-07-29 20:46 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: trepseb at hotmail dot com Assigned: fb-req-jani (profile)
Status: Not a bug Package: Performance problem
PHP Version: 5.2.6 OS: Linux fedora
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: trepseb at hotmail dot com
New email:
PHP Version: OS:

 

 [2008-07-28 12:18 UTC] trepseb at hotmail dot com
Description:
------------
We were using eval extensivly for making a dynamic code parser. It used to be all ok till we needed to use it for more than 30000 iterations. Suddenly our memory limit was reached. We tracked it down to the underlying code.

Strangely this is only an issue with 64 Bit systems. A PowerMac Dual has this Problem the same as a 8 Core XEON. The INTEL and AMD with 32 bits don't have a Problem, here the script requires no additional memory with each cycle.

Probably this has to do with some underlying library, but maybe you can figure out which.

Here is a part of my php info

Linux ******** 2.6.23.17-88.fc7 #1 SMP Thu May 15 00:02:29 EDT 2008 x86_64
Build Date 	May 8 2008 08:38:49
Configure Command 	'./configure' '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib64' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-system-tzdata' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--disable-json'


I checked the other eval errors, but they did not have much to do with mine, and they are all stone old ;).

Reproduce code:
---------------
echo "start ".memory_get_usage()."\n";

$aData['an_anfrage_art'] = '150';

$aData['ega_codes'] = '12|13|15|17|18|23';

for ($i=0;$i<100000;$i++){

   eval('$bCondition = !in_array( \'150\' , array(12,13,15,17,18,23));');

}

echo "end ".memory_get_usage();

Expected result:
----------------
start 46592 
end 47980

32 bit system. This is the expected result the memory usage is constant with more cycles

Actual result:
--------------
start 78488
end 1710444

64 bit system. Here the memory usage is growing linearly. More cycles make the memory consumption grow. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-28 20:17 UTC] jani@php.net
# uname -a
Linux linux5 2.6.20-1.2944.fc6 #1 SMP Tue Apr 10 17:46:00 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

# USE_ZEND_ALLOC=0 php t.php
start 8208
end 8208

# USE_ZEND_ALLOC=1 php t.php
start 92496
end 223888

# USE_ZEND_ALLOC=1 php -n t.php
start 90952
end 94032

Note the last result. The second is with Xdebug enabled. 
Do you by any chance have Xdebug (or any other Zend extension) loaded?
If so, this is quite expected behaviour..

 [2008-07-29 14:13 UTC] trepseb at hotmail dot com
Thank you jani. This really was an issue with a debugger extension. I still don't understand why the "same" debugger does not have a problem in 32 bit systems and why you would see this as expected behaviour, but it works now. Maybe this is something for the zend people to analyze. Until now must developer systems are not 64 bit and it's very difficult to get to the grounds of this on your server alone.
 [2008-07-29 20:46 UTC] jani@php.net
For more info, check bug #41053, bug #40720 which have quite good explanation why this happens.
 [2015-11-17 14:16 UTC] chris at willowsconsulting dot ie
I became interested by the eval() behavior recently, and I can confirm that the memory usage gets higher by the time of the execution.
However it is not really a bug, but the way eval() is fundamentally written:
* it creates a temp file with the code inside (sometimes it is stored in memory)
* it then includes that temp file using a normal include() function

As you can see, the more eval() you do, the more include() it will trigger, resulting in a memory usage that cannot be freed...
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Feb 28 03:01:27 2020 UTC