Count number of MySQL queries executed on page

后端 未结 7 835
慢半拍i
慢半拍i 2020-12-30 07:05

how would I count the number of sql queries executed on one page load?

I have a similar script to time taken for page to be generated, but not for how many queries h

7条回答
  •  情书的邮戳
    2020-12-30 07:43

    After Quassnoi comment i put this in the start of script:

    $res = mysql_query("SHOW SESSION STATUS LIKE 'Questions'");
    $row = mysql_fetch_array($res, MYSQL_ASSOC);
    define("START_QUERIES",$row['Value']);
    

    and this:

    $res = mysql_query("SHOW SESSION STATUS LIKE 'Questions'");
    $row = mysql_fetch_array($res, MYSQL_ASSOC);
    define("STOP_QUERIES",$row['Value']);
    

    you can see total num of queries with:

    echo "No of queries: ".(STOP_QUERIES-START_QUERIES-1);
    

    I don't know why use -1, maybe it counts mysql_select_db statement (or smth) also, but it works pretty good on my localhost

提交回复
热议问题