query time?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • AaronV

    query time?

    Hello,

    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.

    -Aaron

  • NC

    #2
    Re: query time?

    AaronV wrote:[color=blue]
    >
    > I'd like to get the time it took a query to execute.[/color]

    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
    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


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

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

    Cheers,
    NC

    Comment

    Working...