humanmade/query-monitor

Name: query-monitor

Owner: Human Made

Description: A WordPress plugin for monitoring database queries, hooks, conditionals, HTTP requests, query vars, environment, redirects, and more.

Created: 2018-02-23 13:36:40.0

Updated: 2018-02-23 13:36:42.0

Pushed: 2018-02-08 17:25:41.0

Homepage: https://wordpress.org/plugins/query-monitor/

Size: 2743

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

WordPress Plugin Version License WordPress Tested Build Status

Query Monitor

Query Monitor is a debugging plugin for anyone developing with WordPress. It has some advanced features not available in other debugging plugins, including automatic AJAX debugging, REST API debugging, and the ability to narrow down its output by plugin or theme.

Query Monitor adds a toolbar menu showing an overview of the current page. Complete data is shown in the footer once you select a menu item.

Here's an example of Query Monitor's output. This is the panel showing aggregate database queries grouped by component, allowing you to see which plugins are spending the most time on database queries.

Aggregate Database Queries by Component



Features

Database Queries

Filtering queries by component or calling function makes it easy to see which plugins, themes, or functions on your site are making the most (or the slowest) database queries.

Hooks
Theme
PHP Errors
Request
Rewrite Rules
Scripts & Styles
Languages
HTTP Requests
User Capability Checks
Redirects
AJAX

The response from any jQuery AJAX request on the page will contain various debugging information in its headers. Any errors also get output to the developer console. No hooking required.

Currently this includes PHP errors and some overview information such as memory usage, but this will be built upon in future versions.

REST API

The response from an authenticated WordPress REST API (v2 or later) request will contain various debugging information in its headers, as long as the authenticated user has permission to view Query Monitor's output.

Currently this includes PHP errors and some overview information such as memory usage, but this will be built upon in future versions.

Admin Screen
Environment Information
Everything Else
Authentication

By default, Query Monitor's output is only shown to Administrators on single-site installs, and Super Admins on Multisite installs.

In addition to this, you can set an authentication cookie which allows you to view Query Monitor output when you're not logged in (or if you're logged in as a non-administrator). See the bottom of Query Monitor's output for details.

Notes

A Note on Profiling

Query Monitor does not currently contain a profiling mechanism. The main reason for this is that profiling is best done at a lower level using tools such as XHProf.

However, it is likely that I will add some form of profiling functionality at some point. It'll probably be similar to how Joe Hoyle's TimeStack does it, because that works nicely. Suggestions welcome.

A Note on Query Monitor's Implementation

In order to do a few clever things, Query Monitor symlinks a custom db.php into your WP_CONTENT_DIR which means it loads very early. This file gets included before the database driver is loaded, meaning this portion of Query Monitor loads before WordPress even engages its brain.

In this file is Query Monitor's extension to the wpdb class which:

If your WP_CONTENT_DIR isn't writable and therefore the symlink for db.php can't be put in place, Query Monitor still functions, but this extended functionality won't be available. You can manually create the db.php symlink if you have permission.

Screenshots

Admin Toolbar Menu

Admin Menu

Database Queries

Database listing panel showing all queries, and the controls for filtering by query type, caller, and component

Database Queries

A slow database query (over 0.05s by default) that has been highlighted in a separate panel

Slow Database Queries

Aggregate Database Queries by Component

Ordered by most time spent

Aggregate Database Queries by Component

Aggregate Database Queries by Calling Function

Ordered by most time spent

Aggregate Database Queries by Calling Function

Hooks

Hook listing panel showing all hooks, and the controls for filtering by name and component

Hooks

HTTP Requests

Showing an HTTP request with an error

HTTP

Frequently Asked Questions

Who can see Query Monitor's output?

By default, Query Monitor's output is only shown to Administrators on single-site installs, and Super Admins on Multisite installs.

In addition to this, you can set an authentication cookie which allows you to view Query Monitor output when you're not logged in (or if you're logged in as a non-administrator). See the bottom of Query Monitor's output for details.

Does Query Monitor itself impact the page generation time or memory usage?

Short answer: Yes, but only a little.

Long answer: Query Monitor has a small impact on page generation time because it hooks into a few places in WordPress in the same way that other plugins do. The impact is negligible.

On pages that have an especially high number of database queries (in the hundreds), Query Monitor currently uses more memory than I would like it to. This is due to the amount of data that is captured in the stack trace for each query. I have been and will be working to continually reduce this.

Are there any add-on plugins for Query Monitor?

A list of add-on plugins for Query Monitor can be found here.

In addition, Query Monitor transparently supports add-ons for the Debug Bar plugin. If you have any Debug Bar add-ons installed, just deactivate Debug Bar and the add-ons will show up in Query Monitor's menu.

Where can I suggest a new feature or report a bug?

Please use the issue tracker on Query Monitor's GitHub repo as it's easier to keep track of issues there, rather than on the wordpress.org support forums.

Is Query Monitor available on WordPress.com VIP Go?

Yep! You just need to add define( 'WPCOM_VIP_QM_ENABLE', true ); to your vip-config/vip-config.php file.

(It's not available on standard WordPress.com VIP though.)

I'm using multiple instances of wpdb. How do I get my additional instances to show up in Query Monitor?

You'll need to hook into the qm/collect/db_objects filter and add an item to the array with your connection name as the key and the wpdb instance as the value. Your wpdb instance will then show up as a separate panel, and the query time and query count will show up separately in the admin toolbar menu. Aggregate information (queries by caller and component) will not be separated.

Do you accept donations?

No, I do not accept donations. If you like the plugin, I'd love for you to leave a review. Tell all your friends about the plugin too!

Related Tools

Debugging is rarely done with just one tool. Along with Query Monitor, you should be aware of other plugins and tools which aid in debugging and profiling your website. Here are some examples:

Query Monitor also has several add-on plugins which extend its functionality, and transparently supports add-ons for the Debug Bar plugin (see the FAQ for more info).

See also my list of WordPress Developer Plugins.

Contributing

Code contributions are very welcome, as are bug reports in the form of GitHub issues. Development happens in the develop branch, and any pull requests should be made to that branch please.

License: GPLv2

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.