Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 如何显示Wordpress进行的所有数据库查询?_Database_Wordpress - Fatal编程技术网

Database 如何显示Wordpress进行的所有数据库查询?

Database 如何显示Wordpress进行的所有数据库查询?,database,wordpress,Database,Wordpress,使用类似的方法,我可以看到加载页面时在Wordpress中进行的查询总数 现在,我想显示加载页面时进行的所有数据库查询。这将使我能够了解谁是我最大的资源消耗者,而不必经历取消所有插件和主题脚本的过程 显示Wordpress所做的所有数据库查询的最佳方式是什么?如果在配置文件中添加“定义”“保存查询”(define'SAVEQUERIES),则可以通过向主题中添加以下内容来列出当前页面的所有查询 if (current_user_can('administrator')){ global

使用类似的方法,我可以看到加载页面时在Wordpress中进行的查询总数

现在,我想显示加载页面时进行的所有数据库查询。这将使我能够了解谁是我最大的资源消耗者,而不必经历取消所有插件和主题脚本的过程

显示Wordpress所做的所有数据库查询的最佳方式是什么?

如果在配置文件中添加“定义”“保存查询”(define'SAVEQUERIES),则可以通过向主题中添加以下内容来列出当前页面的所有查询

if (current_user_can('administrator')){
    global $wpdb;
    echo "<pre>";
    print_r($wpdb->queries);
    echo "</pre>";
}

有关更多详细信息,请参阅文档:

或者您可以根据请求连接到posts\u。您可以将coe放在functions.php中,例如

print_r($GLOBALS['debugku']);
使用

这是一个免费的开源插件,您可以在其中过滤各种上下文中的查询,例如:

哪个插件调用 耗时最多的查询 重复查询 您可以通过选择/更新/插入/删除进行筛选 除其他外


我想在页面底部添加查询/运行时间,代码如下:


谢谢,这就成功了。现在,我只需要理解一下查询。请注意,如果使用Hyperdb,则需要在db-config.php中执行此操作:$wpdb->save_querys=defined'savequerys'&&savequerys;你能告诉我每个查询的[1]值是多少吗?[1] =>0.0004429817199707感谢您的建议,文档已移至。我喜欢这样,它不需要编辑核心文件,我认为它是有效的,但我不是100%确定。要破译它的输出有点困难。数据看起来很稀疏,但我想可能都在一条线上,我就是看不到所有的数据。我同意上面Richard M的建议,并将其输出到一个格式良好的列表中;这个插件中有大量的信息!我在查询下找到了我要查找的SQL,Caller=Main Query。
print_r($GLOBALS['debugku']);
/**
 * show all sql at footer if it defined in wp-config.php:
 * define('SAVEQUERIES', true);
 */
function plg_name_show_debug_queries()
{
    if (defined('SAVEQUERIES') && SAVEQUERIES) {
        global $wpdb;
        if (is_array($wpdb->queries)) foreach ($wpdb->queries as $key => $q) {
            list($query, $elapsed, $debug) = $q;
            $time = number_format(($elapsed * 1000), 3);
            $count = $key + 1;
            $total_time += $elapsed;
            echo "
            <div style=\"position: relative; z-index: 9999    ; background: black; color: white; padding:10px\">
                $count - Query: $query <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Time: $time ms
            </div>";
        }
        echo "
        <div style=\"position: relative; z-index: 9999    ; background: black; color: white; padding:10px\">
            Total Queries: " . count($wpdb->queries) . "<br>Total Time: " . number_format(($total_time * 1000), 3) . " ms
        </div>";
    }
}
add_action('admin_footer', 'plg_name_show_debug_queries', PHP_INT_MAX);
add_action('wp_footer', 'plg_name_show_debug_queries', PHP_INT_MAX);