Maximum Execution Time and pereg_replace
| From: | Brent Charbonneau | Date: | Wed, 18 Oct 2000 06:07:10 +0000 |
| Subject: | Maximum Execution Time and pereg_replace | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-20798@lists.php.net to get a copy of this message | ||
Hey,
A nasty bug has been bothering me for a while now, and I haven't exactly
been able to figure it out. I've written a rather complex news/webloging
script that uses it's on 'style' templates. I process various tags within
the templates to insert the news article specific info.
Anways, I use preg_replace to do some of the tag/value swaping, and I think
it may be the cause of a maximum execution time error (which I believe
translated to a 100% CPU & PHP process hang in windows). Here is some
example code (quite cut down for simplicity):
$out_text = $this->raw_modify_style;
$out_text = ereg_replace("<!\\-\\-#title#\\-\\->", "$title", $out_text);
$out_text = ereg_replace("<!\\-\\-#input_body#\\-\\->", '<textarea
cols="25"
rows="7" name="input_body">' .
$this->SQLWrap->GetField("Body") .
'</textarea>', $out_text);
.
.
.
$out_text =
preg_replace("/<!--#MODIFY#-->((.|\\n|\\r)*)?<!--#\/MODIFY#-->/", ($step ==
3)?"\\1" : "", $out_text);
Explanation: $this->raw_modify_style is the raw text from the style template
loaded earlier... could be something similar to
http://www.brentc.com/inertianews/modify_style_sample.html
(note it's the
SOURCE of that file (with added tags) that's important here).
The second line is an example of a quick ereg_replace I use to replace one
of my tags with a value.
The third is similar to the second, but replaces the <!--#input_body#--> tag
with an html <textarea> with the contents of the news articles body.
The fourth line is the line that is referenced in the maximum execution
error.
The idea is, is that the 1 style file is for a multi-stepped (in the end
user's eyes) process, and if the it's the 3rd step ($step==3), then I want
to use the stuff from the style file that is enclosed in the <!--#MODIFY#-->
and <!--#/MODIFY#--> tags.
Now, this solution works fine and dandy I'd say maybe 75% of the time. But
it seems whenever the content of the article gets to a certain length, this
craps out, and just hangs on the preg_replace.
What I'm assuming is that $out_text is becoming too large... and therefore
preg_replace can't handle it. But it doesn't seem to be a matter of it just
taking longer and longer, because once the article is made a little bit
shorter, the whole thing runs quite quickly (no where near approaching the
30sec max execution time).
I've found that by moving the last line above the first line (thereby
eliminating any style tags that aren't needed, and getting the preg_replace
in there before $out_text becomes large with the replacement of style tags)
the error almost goes away.... but I feel this solution will limit the
complexity of the style files, as eventually, the $out_text (before ANY
replacements have been made) may exceed the size that preg_replace can
handle.
Anyways, so thats my long explanation.
Can anyone lend any help?
BTW- the full source of this can be found at
http://www.brentc.com/inertianews , it's
located in inertianews_main.php
thanks in advance!
-brent
--
Brent Charbonneau
--
inertianews@brentc.com | www.brentc.com/inertianews