PHP
  Home arrow PHP arrow Page 3 - Using Timers to Benchmark PHP Applications
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Using Timers to Benchmark PHP Applications
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2008-04-30


    Table of Contents:
  • Using Timers to Benchmark PHP Applications
  • Defining a few working classes
  • Displaying database rows without using HTTP compression
  • Displaying database records using HTTP compression

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Using Timers to Benchmark PHP Applications - Displaying database rows without using HTTP compression
    ( Page 3 of 4 )

    As I stated in the section that you just read, the first benchmarking example that I’ll set up will be aimed at determining how long it takes to fetch ten rows from a sample “USERS” MySQL database table. They will be displayed on the browser after the retrieval process. In this case, all these tasks will be performed without using HTTP compression when the data is transferred back to the client.

    Assuming that the sample database table has been populated with the following data,


    ID

    Name

    Email

    1

    user1

    user1@domain.com

    2

    user2

    user2@domain.com

    3

    user3

    user3@domain.com

    4

    user4

    user4@domain.com

    5

    user5

    user5@domain.com

    6

    user6

    user6@domain.com

    7

    user7

    user7@domain.com

    8

    user8

    user8@domain.com

    9

    user9

    user9@domain.com

    10

    user10

    user10@domain.com


    here is the corresponding code sample along with the respective timing results:


    // example without using HTTP compression


    try{

    // instantiate 'Timer' class

    $timer=new Timer();

    // start timer

    $timer->start();

    // connect to MySQL

    $db=new MySQL(array
    ('host'=>'host','user'=>'user','password'=>'password','database'=>'database'));

    $result=$db->query('SELECT * FROM users');

    while($row=$result->fetchRow()){

    echo 'ID: '.$row['id'].' Name: '.$row['name'].' Email: '.$row['email'].'<br />';

    }

    $elapsedTime=$timer->stop();

    // display elapsed time

    echo 'Time spent in fetching database rows was '.$elapsedTime.' seconds';

    }

    catch(Exception $e){

    echo $e->getMessage();

    exit();

    }


    /* displays the following:


    ID: 1 Name: user1 Email: user1@domain.com

    ID: 2 Name: user2 Email: user2@domain.com

    ID: 3 Name: user3 Email: user3@domain.com

    ID: 4 Name: user4 Email: user4@domain.com

    ID: 5 Name: user5 Email: user5@domain.com

    ID: 6 Name: user6 Email: user6@domain.com

    ID: 7 Name: user7 Email: user7@domain.com

    ID: 8 Name: user8 Email: user8@domain.com

    ID: 9 Name: user9 Email: user9@domain.com

    ID: 10 Name: user10 Email: user10@domain.com


    Time spent in fetching database rows was 0.0053 seconds


    /*


    As you can see, the benchmarking script shown above is very simple to grasp. Basically, all it does is time the retrieval of the rows from MySQL, including the connection to the server. Obviously, this process is performed very quickly, since only a trivial query is executed against the sample database table. But in this case, I opted to display the data without using HTTP compression.

    At this point, I’m pretty sure that you understand how to correctly use the “Timer” class that I defined a few lines above. Therefore, it’s time to leap forward and set up a similar example, but this time the database rows will be fetched and sent to the client using HTTP compression.

    Go ahead and read the following section.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek