|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34222 str_replace leaks when replacing text in arrays
Submitted: 2005-08-23 17:56 UTC Modified: 2005-08-31 01:00 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: phpbug at phormix dot com Assigned:
Status: No Feedback Package: Strings related
PHP Version: 4.4.0 OS: Debian Gnu/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
20 - 12 = ?
Subscribe to this entry?

 [2005-08-23 17:56 UTC] phpbug at phormix dot com
Replacing items in an array of  20-30 items with str_replace seems to leak memory. The application in question would crash when parsing various larger CSV files, using upwards to >500MB  per an 18MB data-file. 

Jumps in memory usage were observed at the point where str_replace was run. Using the function 'preg_replace' instead issued no such leak

Reproduce code:
str_replace('~comma~', ',', $myarray );

Expected result:
(values of ~comma~ in string were replaced with actual commas)

Actual result:
Progress would end indicating in logs that the memory limit of 500MB (as indicated in php.ini) was exceeded.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-23 23:47 UTC]
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 to avoid embedding huge scripts into the report.

 [2005-08-31 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 16:01:27 2024 UTC