Results 1 to 3 of 3
  1. #1
    The affiliate formerly known as ojmoo
    Join Date
    January 18th, 2005
    Posts
    1,466
    Post How long is your mysql query taking
    Sometimes you write a query and it is slowing your whole server down but you don't know which query or where that query is coming from. I wrote a program that will find out for you.

    First thing to do is to create an .inc file with the following function.

    <?php
    function mysqlquery( $NewQuery ) {
    $start = microtime(TRUE);
    $theresult = mysql_query( $NewQuery );
    $ended = microtime(TRUE);
    $thetime = $ended - $start;
    $path = $_SERVER['PHP_SELF'];
    $arg1 = $_SERVER['QUERY_STRING'];
    $gfp1 = fopen("query.txt","a");
    $AQuery = str_replace("\n"," ",$NewQuery);
    $AQuery = str_replace("\r","",$AQuery);
    fwrite($gfp1,"$path\t$arg1\t$AQuery\t$thetime\r\n");
    fclose($gfp1);
    return($theresult);
    }
    ?>
    Second add a statement on top of your program to include the file that contains this function. i.e. include ('querytime.inc');

    Third use search and replace on all your php files to change the mysql_query to mysqlquery.

    Let the program run a while and then look at a file called query.txt. It'll show you a list of the pages, query parameters and time it took to run that query. I found this function very useful.

    When finished, simply search and replace again to change the mysqlquery function back to mysql_query

    Feel free to use and modify this function as necessary.
    Expert who says Moo

    a.k.a. OJMOO

    Cow Dance



  2. #2
    OPM and Moderator Chuck Hamrick's Avatar
    Join Date
    April 5th, 2005
    Location
    Park City Utah
    Posts
    16,646
    112 views todate, someone should thank you for the work!

  3. #3
    The affiliate formerly known as ojmoo
    Join Date
    January 18th, 2005
    Posts
    1,466
    No problem. I wrote it for myself a few months ago when I found out something was slowing my server. I probably should have posted it a while back when I created it. Without it I would have never figured out what slowed my server.
    Expert who says Moo

    a.k.a. OJMOO

    Cow Dance


  4. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Need help with MySQL query
    By mobilebadboy in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: January 17th, 2007, 03:00 AM
  2. Exporting MYSQL export query to a text file
    By dflsports in forum Programming / Datafeeds / Tools
    Replies: 3
    Last Post: October 22nd, 2006, 11:49 AM
  3. How to speed up the mulit-condition query of mysql
    By concorde in forum Programming / Datafeeds / Tools
    Replies: 13
    Last Post: July 17th, 2005, 03:38 PM
  4. Help please with mysql query
    By IGshop in forum Programming / Datafeeds / Tools
    Replies: 15
    Last Post: January 19th, 2004, 08:49 AM

Posting Permissions

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