• Stars
    star
    1,580
  • Rank 29,506 (Top 0.6 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 12 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The developer tools panel for WordPress

WordPress Plugin Version License WordPress Tested Build Status

Query Monitor

Query Monitor is the developer tools panel for WordPress. It enables debugging of database queries, PHP errors, hooks and actions, block editor blocks, enqueued scripts and stylesheets, HTTP API calls, and more.

It includes some advanced features such as debugging of Ajax calls, REST API calls, user capability checks, and full support for block themes and full site editing. It includes the ability to narrow down much of its output by plugin or theme, allowing you to quickly determine poorly performing plugins, themes, or functions.

Query Monitor focuses heavily on presenting its information in a useful manner. Here's an example showing aggregate database queries grouped by the components responsible for them:

Aggregate Database Queries by Component


Features

Database Queries

  • Shows all database queries performed during the current request
  • Shows affected rows and time taken for all queries
  • Shows notifications for slow queries, duplicate queries, and queries with errors
  • Shows aggregate query information grouped by type, component, or calling function
  • Queries can be filtered by query type, component, or calling function

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 & Actions

  • Shows all hooks fired during the current request, along with action callbacks, priorities, and components
  • Actions can be filtered by component or name

Theme

  • Shows the template filename and complete template hierarchy
  • Shows all template parts that were requested, and whether they were loaded or not
  • Shows the available body classes
  • Fully supports block themes and full site editing (FSE)

PHP Errors

  • Shows PHP warnings, notices, stricts, and deprecated errors, formatted nicely along with their component and call stack
  • Shows a visible warning in the admin toolbar when necessary

Doing it Wrong

  • Shows usage of "Doing it Wrong" or "Deprecated" functionality in the code on your site

Block Content

  • Shows blocks and associated information from post content and full site editing

Request

  • Shows information about matched URL rewrite rules for the request and corresponding query parameters
  • Shows query variables and highlights any that are custom

Scripts & Styles

  • Shows all enqueued scripts and styles along with their handle, URL, and version
  • Shows their dependencies and dependents
  • Alerts you to any broken or missing dependencies

Languages

  • Shows you language settings and loaded text domains
  • Shows you the requested MO and JSON translation files for each text domain and which ones were loaded

HTTP API Requests

  • Shows all server-side HTTP requests (as long as they use the WordPress HTTP API)
  • Shows the response code, call stack, component, timeout, response size, time taken, and other meta data
  • Alerts you to erroneous responses, such as failed requests and anything without a 200 response code

User Capability Checks

  • Shows every user capability check that is performed, along with the result and any parameters passed along with the capability check

Multisite

  • Shows all calls to switch_to_blog() and restore_current_blog() on Multisite installations

Redirects

  • Whenever a server-side redirect occurs, Query Monitor adds an X-QM-Redirect HTTP header containing the call stack, so you can use your favourite HTTP inspector or browser developer tools to trace where a redirect has come from

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 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 overview information.

To see more detailed information about a REST API request you need to perform an enveloped request which means appending ?_envelope to the requested URL. In this case, Query Monitor will include debugging data in a qm property in the response. Currently this includes database queries (including information about duplicates and errors), HTTP API requests, and transient updates. More information may be added in a future version.

By using the combination of the HTTP headers and the qm property in the response to an enveloped request you'll get good insight into the aspects of a request which have the greatest impact on performance.

Admin Screen

  • Shows the correct names for custom column filters and actions on all admin screens that use a list table
  • Shows the state of get_current_screen() and a few global variables

Environment Information

  • Shows PHP information such as memory limit, error reporting levels, and values of various constants
  • Shows MySQL or MariaDB information, including caching and performance related configuration
  • Shows information about WordPress and the web server
  • Shows version numbers for all the things

Logging

Debugging messages can be sent to the Logs panel in Query Monitor using actions. This works as a good replacement for var_dump():

do_action( 'qm/debug', 'This happened!' );

The logger is PSR-3 compatible, so you can use any of the following actions which correspond to PSR-3 log levels:

  • qm/emergency
  • qm/alert
  • qm/critical
  • qm/error
  • qm/warning
  • qm/notice
  • qm/info
  • qm/debug

A log level of warning or higher will trigger a notification in Query Monitor's admin toolbar.

Contextual interpolation can be used via the curly brace syntax:

do_action( 'qm/warning', 'Unexpected value of {foo} encountered', [
    'foo' => $foo,
] );

A WP_Error, Exception, or Throwable object can be passed directly into the logger:

if ( is_wp_error( $response ) ) {
    do_action( 'qm/error', $response );
}
try {
    // your code
} catch ( Exception $e ) {
    do_action( 'qm/error', $e );
}

A non-scalar value can be passed to the logger and its value will be formatted and output in the same panel.

do_action( 'qm/debug', get_queried_object() );

Finally, the static logging methods on the QM class can be used instead of calling do_action().

QM::error( 'Everything is broken' );

Profiling

Basic performance profiling can be displayed in the Timings panel in Query Monitor using actions in your code:

// Start the 'foo' timer:
do_action( 'qm/start', 'foo' );

// Run some code
my_potentially_slow_function();

// Stop the 'foo' timer:
do_action( 'qm/stop', 'foo' );

The time taken and approximate memory usage used between the qm/start and qm/stop actions for the given function name will be recorded and shown in the Timings panel. Timers can be nested, although be aware that this reduces the accuracy of the memory usage calculations.

Timers can also make use of laps with the qm/lap action:

// Start the 'bar' timer:
do_action( 'qm/start', 'bar' );

// Iterate over some data:
foreach ( range( 1, 10 ) as $i ) {
    my_potentially_slow_function( $i );
    do_action( 'qm/lap', 'bar' );
}

// Stop the 'bar' timer:
do_action( 'qm/stop', 'bar' );

Note that the times and memory usage displayed in the Timings panel should be treated as approximations, because they are recorded at the PHP level and can be skewed by your environment and by other code. If you require highly accurate timings, you'll need to use a low level profiling tool such as XHProf. See the Related Tools section for more information.

Everything Else

  • Shows any transients that were set, along with their timeout, component, and call stack
  • Shows all WordPress conditionals during the current request, highlighted nicely
  • Shows an overview at the top, including page generation time and memory limit as absolute values and as % of their respective limits

Authentication

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

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 when you're logged in as a user who cannot usually see Query Monitor's output. See the Settings panel for details.

Notes

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:

  • Allows it to log details about all database queries (including ones that happen before plugins are loaded)
  • Logs the full stack trace for each query, which allows it to determine the component that's responsible for the query
  • Logs the query result, which allows it to display the affected rows or error message if applicable

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 Toolbar Menu

Database Queries

Database Queries

Capability Checks

Capability Checks

Aggregate Database Queries by Component

Aggregate Database Queries by Component

Aggregate Database Queries by Calling Function

Aggregate Database Queries by Calling Function

Hooks and Actions

Hooks and Actions

HTTP API Requests

HTTP API Requests

Frequently Asked Questions

Does this plugin work with PHP 8?

Yes, it's actively tested and working up to PHP 8.2.

Who can see Query Monitor's output?

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

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 when you're logged in as a user who cannot usually see Query Monitor's output. See the Settings panel 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.

Can I prevent Query Monitor from collecting data during long-running requests?

Yes, if anything calls do_action( 'qm/cease' ) then Query Monitor will cease operating for the remainder of the page generation. It detaches itself from further data collection, discards any data it's collected so far, and skips the output of its information.

This is useful for long-running operations that perform a very high number of database queries, consume a lot of memory, or otherwise are of no concern to Query Monitor, for example:

  • Backing up or restoring your site
  • Exporting a large amount of data
  • Running security scans

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, 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 Altis?

Yes, the Altis Developer Tools are built on top of Query Monitor.

Is Query Monitor available on WordPress.com VIP?

Yes, but a user needs to be granted the view_query_monitor capability to see Query Monitor even if they're an administrator. See the WordPress.com VIP documentation for more details.

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

This feature was removed in version 3.12 as it was rarely used and considerably increased the maintenance burden of Query Monitor itself. Feel free to continue using version 3.11 if you need to make use of this feature.

Can I click on stack traces to open the file in my editor?

Yes! You can enable this on the Settings panel.

Do you accept donations?

I am accepting sponsorships via the GitHub Sponsors program. If you work at an agency that develops with WordPress, ask your company to provide sponsorship in order to invest in its supply chain. The tools that I maintain probably save your company time and money, and GitHub sponsorship can now be done at the organisation level.

In addition, if you like the plugin then I'd love for you to leave a review. Tell all your friends about it too!

Privacy Statement

Query Monitor is private by default and always will be. It does not persistently store any of the data that it collects. It does not send data to any third party, nor does it include any third party resources.

Query Monitor's full privacy statement can be found here.

Accessibility Statement

Query Monitor aims to be fully accessible to all of its users. It implements best practices for web accessibility, outputs semantic and structured markup, uses the accessibility APIs provided by WordPress and web browsers where appropriate, and is fully accessible via keyboard.

That said, Query Monitor does not conform to the Web Content Accessibility Guidelines (WCAG) 2.0 at level AA like WordPress itself does. The main issue is that the user interface uses small font sizes to maintain a high information density for sighted users. Users with poor vision or poor motor skills may struggle to view or interact with some areas of Query Monitor because of this. This is something which I'm acutely aware of and which I work to gradually improve, but the underlying issue of small font sizes remains.

If you've experienced or identified another accessibility issue in Query Monitor, please open a thread in the Query Monitor plugin support forum and I'll try my best to address it swiftly.

Related Tools

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

WordPress Plugins

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.

Other tools

Hosted services

Contributing

Code contributions, feedback, and feature suggestions are very welcome. See CONTRIBUTING.md for more details.

Icon

Query Monitor's icon was designed by Tubagus Didin Asrori.

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.

More Repositories

1

extended-cpts

A library which provides extended functionality to WordPress custom post types and taxonomies.
PHP
971
star
2

wp_mail

Documentation for all the situations where WordPress core sends an email, how and when they happen, and how to filter or disable each one.
344
star
3

wp-crontrol

Take control of the cron events on your WordPress website
PHP
208
star
4

user-switching

WordPress plugin that provides instant switching between user accounts.
PHP
185
star
5

wp-json-schemas

JSON schemas for WordPress PHP objects and REST API responses
TypeScript
139
star
6

extended-template-parts

A library which provides extended functionality to WordPress template parts, including template variables and caching.
PHP
114
star
7

args

Array arguments made bearable
PHP
107
star
8

extended-taxos

PHP
100
star
9

ext

WP-CLI command which checks the existence of PHP extensions needed to run WordPress.
PHP
71
star
10

wp-types

TypeScript definitions for WordPress PHP objects and REST API responses
27
star
11

php-docs-standards

PHPUnit tests for documentation standards of PHP functions and methods.
PHP
24
star
12

wordpress-keyboard-shortcuts

A WordPress plugin which adds keyboard shortcuts for navigation and actions
PHP
23
star
13

wordpress-x

The most powerful and smartest admin toolbar ever in a CMS.
PHP
18
star
14

probot-semver

A GitHub app that provides automatic semantic versioning support
JavaScript
15
star
15

plugin-infrastructure

Reusable infrastructure relating to testing, building, and deploying my WordPress plugins
Shell
13
star
16

user-switching-for-regular-admins

Adds support to the User Switching plugin for regular admins on multisite
PHP
11
star
17

vip-go-indicator

Adds an admin toolbar indicator which identifies the current WordPress.com VIP Go environment
PHP
9
star
18

ideas

Ideas for things that I'll build just as soon as I find the time
8
star
19

global-post-password

WordPress plugin to globally set a password for all password protected posts and pages
PHP
8
star
20

revisions-digest

A WordPress plugin which generates digests of changes to content via their revisions.
PHP
7
star
21

plugin-info

Provides a simple way of displaying up-to-date information about specific WordPress Plugin Directory hosted plugins in your blog posts and pages.
PHP
7
star
22

falsey-assertequals-detector

Marks a PHPUnit test as risky if it tests a falsey value with assertEquals()
PHP
7
star
23

wp-git-status

WordPress plugin that shows the Git branch and current status in the admin toolbar
PHP
6
star
24

extended-widgets

PHP
5
star
25

wctrn-login-lockdown

Login Lockdown plugin for the WordCamp Torino 2018 WP-CLI workshop
PHP
4
star
26

wp-stats

HTML
4
star
27

https-indicator

PHP
3
star
28

php-errors

PHP error handling tests
PHP
3
star
29

slurpetta

Slurps down the most popular plugins and themes from WordPress.org
PHP
3
star
30

wp-contributors-map

A Node.js server for generating a GeoJSON file of contributors to WordPress.
JavaScript
3
star
31

wctrn-site-setup-script

Site setup script for the WordCamp Torino 2018 WP-CLI workshop
Shell
3
star
32

user-switching-duo-security

User Switching add-on plugin so it plays nicely with Duo Security
PHP
3
star
33

PrettyFilters

A proof-of-concept WordPress plugin which adds a much nicer interface to the filters on post listing screens
PHP
3
star
34

qm-self-awareness

Self-profiling plugin for Query Monitor.
PHP
3
star
35

gitattributes-globs

Parse a .gitattributes file and return its export-ignore entries as an array of glob patterns.
JavaScript
2
star
36

resource-host-monitor

PHP
1
star
37

ssl-helper

PHP
1
star
38

.github

1
star
39

johnbillion

1
star