Here are some quick tips taken from phplens.com:
The more you understand the software you are using (Apache, PHP, IIS, your database) and the deeper your knowledge of the operating system, networking and server hardware, the better you can perform global optimizations on your code and your system.
For PHP scripts, the most expensive bottleneck is normally the CPU. Twin CPUs are probably more useful than two Gigabytes of RAM.
Compile PHP with the "configure β-enable-inline-optimization" option to generate the fastest possible PHP executable.
Tune your database and index the fields that are commonly used in your SQL WHERE criteria.
Use HTML caching if you have data that rarely changes. Even if the data changes every minute, caching can help provided the data is synchronized with the cache. Depending on your code complexity, it can improve your performance by a factor of 10.
Benchmark your most complex code early (or at least a prototype), so you get a feel of the expected performance before it is too late to fix. Try to use realistic amounts of test data to ensure that it scales properly.
Consider using a opcode cache. This gives a speedup of between 10-200%, depending on the complexity of your code. Make sure you do some stress tests before you install a cache because some are more reliable than others.
Use ob_start() at the beginning of your code. This gives you a 5-15% boost in speed for free on Apache. You can also use gzip compression for extra fast downloads (this requires spare CPU cycles).
Consider installing Zend Optimizer. This is free and does some optimizations, but be warned that some scripts actually slow down when Zend Optimizer is installed. The consensus is that Zend Optimizer is good when your code has lots of loops.
Optimize your loops first. Move loop invariants outside the loop.
Use the array and string functions where possible. They are faster than writing equivalent code in PHP.
If you have many small PHP scripts that use session variables, consider recompiling PHP using the shared memory module for sessions. Enable this with "configure -βwith-mm" then re-compile PHP, and set session.save_handler=mm in php.ini.
For searching for substrings, the fastest code is using strpos(), followed by preg_match() and lastly ereg(). Similarly, str_replace() is faster than preg_replace(), which is faster than ereg_replace().
Unset() variables that are not used anymore to reduce memory usage. This is mostly useful for resources and large arrays.
Use foreach() for iterating through arrays.
Echo is slightly faster than print because echo does not return a value and (this is more important) there is no need to concatenate strings or variables with echo() β pass them as multiple comma separated arguments:
echo $var1, $var2;
print $var1 . $var2;
For classes with deep hierarchies, functions defined in derived classes (child classes) are invoked faster than those defined in base class (parent class). Consider replicating the most frequently used code in the base class in the derived classes too.
Consider writing your code as a PHP extension or a Java class or a COM object if your need that extra bit of speed.
When concatenating multiple long strings together, consider storing the separate strings in an array and concatenate them using implode(). This can be faster than using the dot operator because the dot operator makes multiple memory allocations, while implode() allocates the string buffer only once. From my benchmarks and on my hardware configuration, the combined string has to be greater than 40K, and each sub-string at least 100 characters, for implode() to offer any performance advantage.
For more informations take a look at http://phplens.com.