Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
High-Performance String Concatenation in PHP
Oct 05, 2010 @ 17:08:08

On the SitePoint PHP Blog there's a new post today looking at performance in string concatenation where they compare some of the different methods for appending values and which might give you that minute edge.

This could be a more important to your application: large string operations are often handled on the server when generating HTML pages. There are no special libraries in the standard PHP installation and string concatenation is implemented using the dot operator. [...] You can also join an array of strings using the implode function.

In order to simulate a larger set of string concatenations, they create a loop of 30,000 and append a simple string - "String concatenation." - each time. One method uses the standard period append method and the other uses implode after appending to an array. The result of their testing is that the array/implode method takes twice as long as the standard period/append operator. Take into account, however, that for most applications, the performance difference will be so small, it wouldn't be noticed.

tagged: performance append string concatenation optimize

Link:

Mike Naberezny's Blog:
PHP Temporary Streams
Oct 20, 2008 @ 12:52:59

Following up on this post from David Sklar, Mike Naberezny has come up with a few methods of his own to come up with his "thousand string concatenations".

It's been a while since David Sklar called out to let a thousand string concatenations bloom. That discussion produced some entertaining suggestions for putting strings together such as using preg_replace and calling out to MySQL with SELECT CONCAT.

Mike goes with a bit different media of choice - the filesystem functions and streams. One example opens a file, writes to the file then rewinds back to the beginning of the stream. He modified this to make it slightly more useful (writing to memory not the file system) and shows how it could be used to make a temporary stream for testing purposes.

tagged: temporary stream concatenation zendlog filesystem

Link:

Stoyan Stefanov's Blog:
JS/PHP string concatenation mistype
Oct 31, 2007 @ 17:04:00

"Cross-over" developers out there (those that use PHP and Javascript on a regular basis) can sometimes get confused by little syntax things. Stoyan Stefanov got tripped up by just such an issue.

The front-end developer is a strange beast who has to jiggle to and fro and code in several languages literally at the same time - javascript, html, css, php or some other server side language, some SQL dialect... No wonder that sometimes we make silly mistakes.

His issue was with appending - in Javascript, it's a plus but in PHP, it's a period. Unfortunately, the problem can be hard to track down since Javascript also has a use for the period operator - treating the preceding thing like an object.

tagged: concatenation syntax javascript append concatenation syntax javascript append

Link:

Stoyan Stefanov's Blog:
JS/PHP string concatenation mistype
Oct 31, 2007 @ 17:04:00

"Cross-over" developers out there (those that use PHP and Javascript on a regular basis) can sometimes get confused by little syntax things. Stoyan Stefanov got tripped up by just such an issue.

The front-end developer is a strange beast who has to jiggle to and fro and code in several languages literally at the same time - javascript, html, css, php or some other server side language, some SQL dialect... No wonder that sometimes we make silly mistakes.

His issue was with appending - in Javascript, it's a plus but in PHP, it's a period. Unfortunately, the problem can be hard to track down since Javascript also has a use for the period operator - treating the preceding thing like an object.

tagged: concatenation syntax javascript append concatenation syntax javascript append

Link:


Trending Topics: