Performance trick with PHP
optimization, Web Development, PHP October 19th, 2007
I was reading some articles - Brazil - about PHP performance and some coders consider to use the following code to find bottlenecks. The reason of that is because a page can be fast processed but very slow loaded. This script will output the the time that the server took to process the page and with Yslow - Firefox plugin - you can check how long it took to load the page.
On the start of the page include the code:
list($usec, $sec) = explode(’ ‘, microtime());
$script_start = (float) $sec + (float) $usec;
On the end of the page include this code:
list($usec, $sec) = explode(’ ‘, microtime());
$script_end = (float) $sec + (float) $usec;
$elapsed_time = round($script_end - $script_start, 5);
echo $elapsed_time;
Posts
Leave a Comment
You must be logged in to post a comment.