Date: 04/27/99
- Next message: rasmus: "[PHP-DEV] CVS update: php3"
- Previous message: makayg <email protected>: "[PHP-DEV] Bug #1351: memory leak found in two functions: eval and include"
- In reply to: makayg <email protected>: "[PHP-DEV] Bug #1351: memory leak found in two functions: eval and include"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
This is an intentional, and (I believe) documented behavior of eval(), and
include() behaves the same, all the way since PHP 3.0 alpha 1.
There's actually a very good reason for these functions to leave a memory
footprint behind - if you declare functions or classes inside an eval(),
PHP needs to be able to access it even after eval() finishes, and same goes
for include(). Unfortunately, PHP 3.0 doesn't have the means to tell
whether it needs to save the allocated memory or not, so it always saves
it. eval() or include() inside a loop *will* leak memory.
There's no workaround for eval() and include(). However, there should be
almost no circumstances where you'd want to run include() in a loop, unless
you include a lot of different files, in which case there's really nothing
you can do.
If your loop has an include() statement (in PHP 3.0 eval() and include()
are statements, not functions) that repeatedly includes the same file, you
should be using require(). Require() is similar to the C #include
directive, in the sense that it'll run exactly once, and merge the extra
file into the calling file seamlessly.
As a side effect of Zend's implementation, PHP 4.0 will be much lighter
with memory consumption with include() and eval(). Essentially, only the
information that needs to be saved from the eval()'d or the include()'d
code is retained, and the rest is deallocated. Initial PHP 4.0 betas are
likely to be released within less than two months.
Zeev
At 07:23 27/04/99 -0000, makayg <email protected> wrote:
>From: makayg <email protected>
>Operating system: Linux
>PHP version: 3.0.7
>PHP Bug Type: Performance problem
>Bug description: memory leak found in two functions: eval and include
>
>This is the test.phtml script:
>---------------------------------------------
><?PHP
>for ($i=0;$i<5000;$i++)
>{
> echo "$i: ";
>// Uncomment one of the following two lines
> include("hello.phtml");
>// eval("echo 'Hello<BR>\n';");
> flush();
>}
>?>
>---------------------------------------------
>
>This is the hello.phtml script:
>---------------------------------------------
>Hello<BR>
>---------------------------------------------
>
>Uncomment one of the "include" or "eval" lines (the script behaves the
same in both cases), then run
> php -f test.phtml
>then you will get the following fatal error after about 4095 lines of output:
> Unable to initialize a new token in cache
>
>Checking the memory usage in the whole system, it turns out that this test
script quickly fills up about 30 Mb of memory, then stops with the above
error. Version 3.0.5 had a similar problem, although it filled up only
about 5 Mb, and did not stop after about 4095 lines (I tried with with
100000 in the "for" cycle), but rather filled up all memory the computer
had. If I run this script through an Apache module, then in all cases it
stops after about 4095 lines. The settings of the php3.ini file seem to be
irrelevant, even the memory_limit option. Anyway, I only changed the
default configuration in the max_execution_time option, and I included the
mysql extension. I downloaded the binary 3.0.5 version from the Debian
site, and I compiled the 3.0.7 version with no option (I simply said
"./configure").
>
>Since "eval" and "include" behave very similarly, I assume, that the
problem is in a subfunction of these functions. There does not seem to be
any reason, why these functions should leave memory behind after their run.
>
>I could get rid of "eval" from my program (almost), but I do need
"include", I use it to regenerate our WWW pages from templates.
>
>Please, tell me, if you received this message, or if you have a solution
or workaround.
>
>Thank you very much for your attention.
>
>Sincerely yours,
>
>Geza Makay
>
>
>
>--
>PHP Development Mailing List http://www.php.net/
>To unsubscribe send an empty message to php-dev-unsubscribe <email protected>
>For help: php-dev-help <email protected>
>
>
>
-- Zeev Suraski <zeev <email protected>> http://www.zend.com/ For a PGP public key, finger bourbon <email protected>-- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe <email protected> For help: php-dev-help <email protected>
- Next message: rasmus: "[PHP-DEV] CVS update: php3"
- Previous message: makayg <email protected>: "[PHP-DEV] Bug #1351: memory leak found in two functions: eval and include"
- In reply to: makayg <email protected>: "[PHP-DEV] Bug #1351: memory leak found in two functions: eval and include"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

