SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    What is best way to get the time it took for Php MySQL to process a Query?

    Hallo,

    What is best way to get the time it took for Php MySQL to process a Query?
    I am doing this currently:
    1- When the Query is POSTED I set:
    $t1 = $_SERVER['REQUEST_TIME'];

    2- When the Query is done, that is after:
    mysql_query($sql_chk_url) or die(mysql_error());
    I set:
    $t2 = $_SERVER['REQUEST_TIME'];

    However, $t1 $t2 are always the same even though it takes like 5 seconds for the page to come back vs 1 second. etc.

    What to do?

    Thanks.

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,179
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    $_SERVER['REQUEST_TIME']; will display the time in which the request was made, not the current time... You could run a difference between that and time() at the very end of your script for a full page process time. Use time() before and after your query for your query process time.

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I switched to time(); for getting $t1 & $t2, but I still see a difference of 0.000
    between the 2!


    Quote Originally Posted by K. Wolfe View Post
    $_SERVER['REQUEST_TIME']; will display the time in which the request was made, not the current time... You could run a difference between that and time() at the very end of your script for a full page process time. Use time() before and after your query for your query process time.

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,179
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    Bah, ok microtime() then.. See examples on http://php.net/manual/en/function.microtime.php

  5. #5
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I did as you suggested.
    That is now I have at the start of the page:
    $t1 = microtime();

    and at the end of the page after the Query is down and the page generated:

    $t2 = microtime();

    however, some of the time I get a Negative value! What the HEK!

    Anoox search engine volunteer

    www.anoox.com

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,258
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    This should be super simple, but actually microtime requires a careful reading of the manual.

    Return Values

    By default, microtime() returns a string in the form "msec sec" ... If get_as_float is set to TRUE, then microtime() returns a float
    So microtime() is useless for any kind of math, and you should almost always use microtime(true).
    "First make it work. Then make it better."

  7. #7
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    That seems to work fine. That is microtime(true) results in more negative time diffs.

    ThanX

    Quote Originally Posted by Jeff Mott View Post
    This should be super simple, but actually microtime requires a careful reading of the manual.

    So microtime() is useless for any kind of math, and you should almost always use microtime(true).

    Anoox search engine volunteer

    www.anoox.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •