PHP Script to Check the Page Speed


I have been doing some SEO (Search Engine Optimisation) work lately to my website and now the page speed has improved quite a lot. In [here], it describes the process of building the cache for the website. The cache pages will automatically build up upon the first visits from e.g. google spiders or human visitors. Does the caching really improve the page speed? We have got to insert some code to compare the performance before and after caching.

The following PHP code will record a time at the begining of PHP code and start the output buffer using ob_start() at the end of the page or right before ob_end_flush() using ob_get_length() will return the length in the output buffer.

1
2
3
4
5
6
7
$starttime = microtime(); // default returns time as string
ob_start(); // start output buffer
echo "lots of code after";
echo "lots of code after";
readfile($cachepage); // at some point read cache index file
$_rt = microtime() - $starttime; // page response time
$sp = round((ob_get_length() / $_rt) / 1024, 3); // speed in KB/s
$starttime = microtime(); // default returns time as string
ob_start(); // start output buffer
echo "lots of code after";
echo "lots of code after";
readfile($cachepage); // at some point read cache index file
$_rt = microtime() - $starttime; // page response time
$sp = round((ob_get_length() / $_rt) / 1024, 3); // speed in KB/s

It is observed that the cached pages are a lot faster than the un-cached ones because simply reading a cached html file is quicker than lots of PHP processing code. The performance speed up, however, depends on pages, which can vary from e.g. from 2 to 10.

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
279 words
Last Post: HTML5 contenteditable Global Attribute
Next Post: Google Adsense Estimated Earnings

The Permanent URL is: PHP Script to Check the Page Speed

4 Comments

  1. HTML5 Speedtest
  2. Md Azad
  3. Prosperity Kenneth

Leave a Reply