php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40236 echo ... | php -a function allocation eats memory
Submitted: 2007-01-25 13:17 UTC Modified: 2007-02-15 10:44 UTC
From: csaba at alum dot mit dot edu Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2007-01-25 (snap) OS: Win XP
Private report: No CVE-ID: None
 [2007-01-25 13:17 UTC] csaba at alum dot mit dot edu
Description:
------------
The following command line (single line in the cmd window) call does not work unless memory_limit is set to 9M or higher in php.ini on my Win XP Pro:

echo ^^^<?php $p='function f';$s='(){}';
for($i=0;++$i^^^<7;) eval($p.$i.$s);
print('success'); ?^^^> | php.exe -a

It complains about having run out of memory:
Interactive mode enabled


Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 786432 bytes) in C:\phpLib\-(1) : eval()'d code on line 1



Reproduce code:
---------------
<?php
// name this file test.php
function func1() { }
function func2() { }
function func3() { }
function func4() { }
function func5() { }
function func6() { }
function func7() { }
print ('success');
?>

The invocation line above looks a little scary (but it's just a loop to define functions) - the below single line achieves the same result:
echo ^^^<?php include('test.php'); ?^^^> | php -a

Expected result:
----------------
I expect the default configuration (of 8M) to be more than enough for trivial code to be invoked with the -a option.
Indeed,
php.exe -r "include(test.php);"
works just fine

It seems like each function declaration gobbles over 1M of memory when php is invoked with the -a option.  I use the -a construct frequently since php-cgi.exe does not allow the -r construct, and I've noticed that between July and December of 2006 is when this problem started happening.

In particular, I have an auto_prepend_file with about 50 functions defined and for php to start running on this requires that I set memory_limit to 56M minimum so that the php invocations with -a can run!

Actual result:
--------------
Tested on the most recent snaps of PHP 5.2 and PHP 6.

Csaba Gabor from Vienna

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-25 14:00 UTC] tony2001@php.net

 [2007-02-15 10:44 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_2.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC