ID: 27176 Updated by: [EMAIL PROTECTED] Reported By: gaz at fission dot org dot uk -Status: No Feedback +Status: Assigned Bug Type: Performance problem Operating System: Slackware 9.1 Linux 2.6.1 kernel PHP Version: 5.0.0b3 (beta3) -Assigned To: +Assigned To: pollita New Comment:
<?php ini_set("memory_limit", "12m"); $replacement = str_repeat("x", 12444); $string = str_repeat("x", 9432); $key = "{BLURPS}"; $string = str_replace($key, $replacement, $string); ?> Previous Comments: ------------------------------------------------------------------------ [2004-02-13 10:15:05] [EMAIL PROTECTED] No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you. preg_replace() might be good alternative too.. ------------------------------------------------------------------------ [2004-02-07 14:01:57] [EMAIL PROTECTED] Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If possible, make the script source available online and provide an URL to it here. Try avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2004-02-07 06:29:06] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27176&edit=1