MySQL query time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

MySQL query time

Post by bluenote »

Hi there,

i am working on a middle-size PHP / MySQL based website. The normal output should just be on display (and it is ;-)), but in some special cases - if the user can fill out a form to search for a certain product - i want to display the time mysqld

Code: Select all

(3.23.52 on SOLARIS 7 SPARC / PHP 4.2.2)
needed to perform this search. The dispaly should be like

Code: Select all

$numrows from a total of $tnumrows result(s) Query time about $........
Has anyone a good idea??

TiA
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

From the manua (slightly tweaked)l:

Code: Select all

<?php
function getmicrotime() { 
    list($usec, $sec) = explode(' ',microtime()); 
    return ((float)$usec + (float)$sec); 
} 

$time_start = getmicrotime();

  #Do your query here

$time_end = getmicrotime();
$time = $time_end - $time_start;

echo 'it took '.$time.' seconds';
?>
User avatar
bluenote
Forum Commoner
Posts: 93
Joined: Sat Mar 01, 2003 4:59 am
Location: Heidelberg, Germany

MySQL query time - Reply from Stoker

Post by bluenote »

THANX-A-LOT!!

This works pretty good. And, with variable name modifications, I can use it for multiple querys in one script.

For anyone else has got the same prob like I had, here is a extension:

Code: Select all

<?php
function getmicrotime() { 
    list($usec, $sec) = explode(' ',microtime()); 
    return ((float)$usec + (float)$sec); 
} 

$time_start = getmicrotime(); 

  #Do your query here 

$time_end = getmicrotime(); 
$time = $time_end - $time_start;

echo "It took<B>"; printf("%17.2f\n", $time); echo"</B> seconds to perform this query\n";

?>
With this, $time comes in the 0,02 fomat.

Greez to all, bluenote
Post Reply