Speeding Up PHP Applications
Nothing you probably haven’t heard before. Just some quick notes which might help speed up a PHP application and my opinions on them.
I tested these theories out based on the difference of
microtime() at the start and beginning of execution over 100000 for loops. This is in no way a complete test.
else ifis slower than
elseif. Doing a find and replace for all your code is a quick way to achieve a good speed up.
Opinion: Yes, interestingly this makes a significant difference.
preg_replaceadds extra processing time. Try to use the built-in string functions instead.
Opinion: Yes of course, this made a difference. Even stacking function such as
trimtogether were faster.
include_onceadds extra work checking too see if the file has already been required/included. Rework your code to use just
Opinion: Yes this made a difference.
Try using single quotes (
') rather than double quotes (
") where possible, i.e. when not using line breaks or carriage returns. also When using
echoand concatenating strings, try using commas (
,) rather than periods (
Opinion: This made a very small, negligible difference to processing time.
And that’s it for now…
Follow up: I found this phpbench.com