0

I'm curious if there's any low hanging fruit to speed up a PHP script.

For example, is one of these better/faster than the other?

//Code 1
echo 'Hello ' . 'World';


//Code 2
echo 'Hello ';
echo 'World';

Are there other ways to clean up code and make it a tad faster? Is it even worth it?

5

2 Answers 2

5

http://hungred.com/useful-information/php-micro-optimization-tips/

But then you have to balance that with how readable and understandable your code is.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, pretty much every low hanging fruit on one page, thanks.
Thanks for the accept! However even as I replied I was shaking my head. As said here (and many other places) this kind of micro-optimisation is rarely needed, you are much better off trying to reduce the number of trips to the database, or work out how you can cache some of your data. These have massive effects. Its like spending big money on fancy car tyres to reduce drag when you have a roofrack on your car and you drive with the windows down. If you ARE into this though, look at XDebug and xdebug.org/docs/profiler . Good luck!
Cool... actually this comment is part of the answer I was looking for: "Is it even worth it?" Also, the suggestion to skip PHP microoptimization and look for DB optimization. Thanks
0

The fastest is probably

echo "Hello ", "World";

if you have to echo two seperate strings/variables, as this avoids having to concatenate the strings. However, the difference is probably unnoticeable for any reasonable sized application.

But remember

Premature optimization is the root of all evil - Donald Knuth

However, it is nice to know the echo-comma syntax and use it where possible.

1 Comment

according this, thegeekstuff.com/2014/04/optimize-php-code your code should be optimized.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.