Re: preg_replace w/evaluations eats memory

From: Date: Sat, 19 Aug 2000 18:02:14 +0000
Subject: Re: preg_replace w/evaluations eats memory
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-29693@lists.php.net to get a copy of this message
The problem was with evaluating PHP code. It was fixed by Zeev today. On Thu, 17 Aug 2000, chrism wrote: > I've not had much luck using the bug system with lynx, so i'll dump > this one here. > > If someone could submit, thanks. > > chrism@four.net > > <?php > > /* > This program demonstrates a memory problem with preg_replace and > evaluations. The memory requirements of the script increase with > each iteration. > > My original script was processing 2000 files, each with 10 preg > operations - hence 20,000 iterations. It's memory usage skyrocketed > to over 270mb. > > This was tested on a FreeBSD 3.3 system with php4-200007141145 > */ > > > /* create a virtual source file */ > $data = str_repeat("xzxzxzxzxzxzzxxz<TAG>memory</TAG>zxzxzxzxzxz", 10); > > > function replace_eval($string) { > /* do nothing */ > } > > > function replace() { > global $data; > > $result = preg_replace("/(?x) > (<\/?) # 1 opening tag > (\w+) # 2 tag > ([^>]*>) # 3 closing tag > ([^<]*) # 4 body > /e", > > "'replace_eval(\\4)'", > > $data); > } > > > function loop() { > for ($i = 0; $i < 20000; $i++) { > replace(); > } > } > > loop(); > > ?> > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > -Andrei Nobody tried to design Windows - it just grew in random directions without any kind of thought behind it.

« previous php.dev (#29693) next »