Skip to content

PHP – Page Generation Time

This little snippet of code will enable you to put a page generated in bit at the bottom of your pages. function maingetmicrotime() { list($usec, $sec) = explode(" ",microtime()); return((float)$usec + (float)$sec); } function page_start() { global $TheStartTime; $TheStartTime = maingetmicrotime(); // Save the current time in a global variable } function page_end() { global $TheStartTime; print("Page Generated in " . round(maingetmicrotime() - $TheStartTime, 2); . "seconds."); // Calculate the difference between the start time and now // Then print out the message } To use this, include this file then call page_start(); at the begginning of your script and right at the end call page_end(); Simple and it gives you an idea of server load. For those after a more object based method for doing the same, I have updated this article with the following snippet of code class timediff { var $startTime; // The start time saved at construction function __construct() { // Save the start time $this->startTime = $this->getMicroTime(); } function getMicroTime() { list ($usec, $sec) = explode (" ",microtime ()); return ((float)$usec + (float)$sec); } function getDiff() { return round ($this->getMicroTime() - $this->startTime, 2); } }

Published inPHP

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.