Page 1 of 1

MySQL query time

Posted: Sat Mar 01, 2003 4:59 am
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

Posted: Sat Mar 01, 2003 10:55 am
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';
?>

MySQL query time - Reply from Stoker

Posted: Sun Mar 02, 2003 2:29 am
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