计算页面上执行的MySQL查询的数量 [英] Count number of MySQL queries executed on page

查看:76
本文介绍了计算页面上执行的MySQL查询的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算一页加载时执行的sql查询的数量?

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 have been executed.

您知道我的意思,例如在SMF论坛的页脚中,它们具有:

You know what I mean, such as on SMF forums, in the footer, they have:

页面在0.136秒内创建了7个查询.

Page created in 0.136 seconds with 7 queries.

在页脚中?

替换所有mysql_query并不是一个真正的选择,有太多的mysql_queries可以替换,尽管如果需要我可以花一天时间.

Replacing all of the mysql_query(ies) isn't really an option, there are way too many mysql_queries to replace, although I could spent a day doing it if needs be.

谢谢

推荐答案

SMF通过具有自己的自定义查询功能来进行查询计数:

SMF does its query counting by having its own custom query function:

function db_query($db_string, $file, $line)
{
    global $db_cache, $db_count, $db_connection, $db_show_debug, $modSettings;

    // One more query....
    $db_count = !isset($db_count) ? 1 : $db_count + 1;

    ...

实现您想要做的事情的最简单方法是做同样的事情.为mysql_query创建一个包装器,并使用它而不是mysql_query.

The simplest way to achieve what you're trying to do would be to do the same; make a wrapper for mysql_query and use that instead of mysql_query.

这篇关于计算页面上执行的MySQL查询的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆