From:             gaz at fission dot org dot uk
Operating system: Slackware 9.1 Linux 2.6.1 kernel
PHP version:      5.0.0b3 (beta3)
PHP Bug Type:     Performance problem
Bug description:  str_replace tries to use obscene amounts of ram

Description:
------------
When str_replace is called with the 'mixed replace' value set to a string
with a large (eg, 16,000) characters in it, it suddenly tries to asign an
absolutly obscene amount of memory.

Reproduce code:
---------------
/* In the code that initially showed this up, $somefile was a 20kb html
file, and $replacefile was a 6kb html file */

$input_text = file_get_contents($somefile);
$replace = file_get_contents($replacefile);
$match = "__RECENT__";

$output = str_replace($match,$replce,$input_text);

Actual result:
--------------
The actual code tries to allocate about 34MB of memory to do this
str_replace. I think it keeps trying to reorder the char[] array, and so a
large replacement string ties it up for a while. Changing to use explode()
and foreach() tends to do the same thing but in no time, and without the
huge memory tie-up.

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

Reply via email to