RE: [PHP-WIN] Re: Performance tuning #2

From: Date: Fri, 04 Jan 2002 07:09:38 +0000
Subject: RE: [PHP-WIN] Re: Performance tuning #2
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-11293@lists.php.net to get a copy of this message
Dear Alek, Thanks for the tips. The implode one seems to work pretty well, on a synthetic test it is ~4-5 times faster than .= The substr_replace() seems to be much worse than the original .=, I suppose because of returninng the whole string in each call; the result should be much better with a var-parameter version... Thanks again, Peter -----Original Message----- From: Alek Andreev [mailto:alek@post.com] Sent: Monday, December 31, 2001 2:35 PM To: Peter Illes Subject: Re: [PHP-WIN] Re: Performance tuning #2 There are two ways to do that: Method 1: Add each new part of the result to an array and when it's done, implode() the array to get the resulting string. Example: (get_data is your custom function) while($data = get_data()) { $resultA[] = $data; } $result = implode($resultA,''); Method 2: Create an empty string ( $buffer = str_pad('',1024); ) and replace parts of it with {$data = get_data(); $buffer = substr_replace($buffer,$data,$i,$i+strlen($data)); $i += strlen($data);}. This is not going to be pretty quickly unless PHP optimizes it, but it's worth a try because in the best case, it can be reduced down to a single memcpy(); If you had a function like substr_replace() that updated the parameter, instead of returning the new string, it would surely work. -- Regards, Alek Andreev alek@post.com ----- Original Message ----- From: "Peter Illes" <pilles@pannonrex.com> To: <php-windows@lists.php.net> Sent: Sunday, December 30, 2001 5:01 PM Subject: [PHP-WIN] Re: Performance tuning #2 > Some more details: > > We are implementing a Web Services server (essentially SOAP server) in PHP > and one of the calls has to return a data packet as XML so we want to > accumulate the response in a string variable and then return it (optionally > logginig it for security reasons). > > We would like to avoid using external files for the accumulation, since we > need some good performance and typically disk v.s. memory cannot compete > (the server has enough RAM;-). > > "Peter Illes" <pilles@pannonrex.com> wrote in message > news:20011230134305.48626.qmail@pb1.pair.com... > > Hi, > > > > This is the second post of this problem since I did not get any answer for > > the first. Please, could someone out there help? Thanks in advance... > > > > I wonder if there is any performance tuning newsgroup/faq/whatever related > > to PHP. I searchead to no avail... > > > > Anyway, my current mind boggler is: we are accumulating a large (~400k) > XML > > response in a string before sending it out by adding little pieces a time > > (like 10-20 chars). Now this results in very bad performance -- most > > probably due to the fact that the string is enlarged/re-allocated > thousands > > of times. I would love to pre-allocate a big buffer for the string so that > > performance gets better (something like SetLength() in Delphi). How can I > do > > this? > > > > Xuse me if the answer is much too trivial, I'm a newbie in PHPland :-) > > > > Thanks for any suggestion, > > > > Peter > > > > > > > > > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.windows (#11293) next »