A while back I launched WebSpeedTest.co.za which is just a little script to check how long it takes to load your website. It doesn’t take into account loading of all objects on the website, just the HTML.
Some of the code can be used in your PHP script to see how long it takes to load.
First what you do is add this at the very top of your script.
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time;
That will have recorded your start time in the variable $start.
Now, at the very end of your script add this in:
$time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4);
$total_time now contains the amount of seconds it took to run your script. This can be useful for debugging to check where you might have bottlenecks.
Instead of the normal if-else statements that most of us are use to, why not start using ternary operators.
Normal if-else statement:
if (empty($v)) { $action = 'default'; } else { $action = $v; }
Replacing the above 5 lines of code with just one line of code:
$action = (empty($v)) ? 'default' : $v;
This might not increase the actual performance of the execution, but it does use fewer lines to code the same thing as well as making it easier to read. Make sure not to use more than one ternary operator in a single statement, as PHP doesn’t always know what to do in those situations.