Date Time Code

  Home arrow Date Time Code arrow Page Generation Time Figure-Outer
DATE TIME CODE

Page Generation Time Figure-Outer
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2005-02-08

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    Well, here it is... the new, faster, safer, easier and all around better class to easily assist you in determing the time it takes to generate a php page.


    This code is extremely simple, yet extremely powerful. All the bugs have been ironed out and it has been streamlined and optimized to deliver the goods in an extremely easy and fast little package.

    The code is compatible with php 4 & 5 and is extremely easy to implement... simply, include the page, declare the class and you're good. After that, place the start() function where you want to begin timing, the stop() function where you want to end timing, and the gen() function where you want to display the time. the gen function simply returns the value, so make sure to utilize it inside of a print() or echo() command. The gen() function must also be after the stop() function, obviously. In addition, if you so wish, you are given the opportunity to change the decimal place to which the returned value is rounded too... simply modify the $change_to variable, it defaults to 4. Below is an example implementation...

    include_once('class.pagegen.php');
    $pagegen = new page_gen();
    $pagegen->round_to = 7;
    $pagegen->start()

    // all of your php code

    $pagegen->stop();
    print('page generation time: ' . $pagegen->gen());

    By : jam wil

    <?php
    class page_gen {
    //
    // PRIVATE CLASS VARIABLES
    //
    var $_start_time;
    var $_stop_time;
    var $_gen_time;

    //
    // USER DEFINED VARIABLES
    //
    var $round_to;

    //
    // CLASS CONSTRUCTOR
    //
    function page_gen() {
    if (!isset($this->round_to)) {
    $this->round_to = 4;
    }
    }

    //
    // FIGURE OUT THE TIME AT THE BEGINNING OF THE PAGE
    //
    function start() {
    $microstart = explode(' ',microtime());
    $this->_start_time = $microstart[0] + $microstart[1];
    }

    //
    // FIGURE OUT THE TIME AT THE END OF THE PAGE
    //
    function stop() {
    $microstop = explode(' ',microtime());
    $this->_stop_time = $microstop[0] + $microstop[1];
    }

    //
    // CALCULATE THE DIFFERENCE BETWEEN THE BEGINNNG AND THE END AND RETURN THE VALUE
    //
    function gen() {
    $this->_gen_time = round($this->_stop_time - $this->_start_time,$this->round_to);
    return $this->_gen_time;
    }
    }
    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Date Time Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    DATE TIME CODE ARTICLES

    - DaysInSpan.php
    - MySQLdateSpan.php
    - DateSpan.php
    - FutureDateFormEntry.php
    - Generate Time Option List for Select stateme...
    - Current Age Script (v2)
    - class for some mysql imitated time functions
    - Current Age Script, up to the last day
    - filemtime_remote
    - Page Generation Time Figure-Outer
    - convGMT v2
    - Benchmarker
    - Simple PHP Calendar
    - Display message according to hour of day
    - Display Date Function

    Developer Shed Affiliates

     



    © 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap