query time?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


I'd like to get the time it took a query to execute. Is there a PHP or
MySQL function that would return the execute-time of the query into a
useable format?

Similar to the way Google displays how long a search takes.


Re: query time?

AaronV wrote:
Quoted text here. Click to load it

OK, so you can run microtime() before executing the query,
then again after executing the query, compute the difference,
and output the result.

The following example is based on code snippet given at
http://www.php.net/microtime :

function microtime_float()
  list($usec, $sec) = explode(" ", microtime());
  return ((float)$usec + (float)$sec);

$time_start = microtime_float();
$result = mysql_query('Your query here');
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "The query took $time seconds";


Site Timeline