Notices
Reply

Thread: How long is your mysql query taking

 
Tools Search
  #1  
Old August 24th, 2011, 05:09 AM
The affiliate formerly known as ojmoo
Join Date: January 18th, 2005
Posts: 1,275
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.

Quote:
<?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  
Old August 31st, 2011, 12:18 AM
ABestWeb Admin
Join Date: October 5th, 2005
Location: Park City Utah
Posts: 9,095
Send a message via AIM to Chuck Hamrick Send a message via MSN to Chuck Hamrick Send a message via Yahoo to Chuck Hamrick
112 views todate, someone should thank you for the work!
  #3  
Old August 31st, 2011, 04:37 PM
The affiliate formerly known as ojmoo
Join Date: January 18th, 2005
Posts: 1,275
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

Join ABW to remove this sponsored message.
Reply

Tools Search
Search:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with MySQL query mobilebadboy Programming / Datafeeds / Tools 3 January 17th, 2007 02:00 AM
Exporting MYSQL export query to a text file dflsports CGI and PHP Programming 3 October 22nd, 2006 10:49 AM
How to speed up the mulit-condition query of mysql concorde Datafeeds 13 July 17th, 2005 02:38 PM
Help please with mysql query IGshop CGI and PHP Programming 15 January 19th, 2004 07:49 AM


Content Relevant URLs by vBSEO ©2011, Crawlability, Inc.