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.