|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-02-07 06:29 UTC] gaz at fission dot org dot uk
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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 21:00:01 2025 UTC |
<?php ini_set("memory_limit", "12m"); $replacement = str_repeat("x", 12444); $string = str_repeat("x", 9432); $key = "{BLURPS}"; $string = str_replace($key, $replacement, $string); ?>