Skip to content

Query Monitor

The Query Monitor WordPress plugin is a powerful debugging tool designed to help developers analyse and troubleshoot their WordPress sites. It provides detailed insights into various aspects of the site’s performance and behaviour. Here are some of the key features and functions of the Query Monitor plugin:

NameAvailable
development
staging
production

You can change these settings in the environments folder located here: config/environments.

  • Query Analysis: Displays all database queries made on a page, including the time taken and the function that called each query.
  • Slow Queries: Highlights slow queries that might be affecting performance.
  • Duplicate Queries: Identifies duplicate queries that could be optimised.
  • Error Logging: Captures and displays PHP errors, warnings, and notices.
  • Error Context: Provides context about where the errors occurred in the code.
  • Hook Overview: Lists all the hooks that fired during a page request, along with their callbacks and execution order.
  • Action and Filter Analysis: Shows the actions and filters applied during the request.
  • External Requests: Tracks outgoing HTTP requests, including API calls, and displays their duration and status.
  • Enqueued Files: Lists all enqueued scripts and stylesheets, along with their dependencies and load order.
  • Server Details: Provides details about the server environment, including PHP and MySQL versions.
  • WordPress Configuration: Shows information about the WordPress configuration and settings.
  • Current User: Displays the capabilities and roles of the current user.
  • Page Context: Lists the WordPress conditional tags that are true for the current request.
  • Request Details: Provides debugging information for Ajax and REST API requests.

Query Monitor is highly useful for developers during development and debugging processes. It helps in identifying performance bottlenecks, debugging errors, and understanding the behaviour of a WordPress site in great detail. The plugin can be accessed from the admin toolbar, making it easy to use while navigating the site.

Profiling can be super useful to identify slow moving parts of your theme.

Result can be found in the Query Monitor Panel under the tab Timings.

The start method is used to start the profiling session, this method requires a string which is used as an identifier.

use App\Util\QueryMonitorUtil;
// Start a profiling session with the name 'foo'
QueryMonitorUtil::start('foo');

The stop method is used to stop and gather all the information about the profiling session, this method requires a string which is used as an identifier this should be the same as the start method.

use App\Util\QueryMonitorUtil;
// Stop the profiling session with the name 'foo'
QueryMonitorUtil::stop('foo');

The lap method is used in loops to check every iteration, this method requires a string which is used as an identifier this should be the same as the start method.

use App\Util\QueryMonitorUtil;
// Add a lap to the profiling session with the name 'foo'
foreach($items as $item) {
QueryMonitorUtil::lap('foo');
}

All these profiling functions are also available in Twig!

{{ qm_start('foo') }}
{{ qm_lap('foo') }}
{{ qm_stop('foo') }}

Query Monitor allows developers to perform assertions which will log an error in the Logs panel in Query Monitor when they fail. This is a convenience wrapper around the logging feature which allows you to get alerted to problems without performing conditional logic.

Result can be found in the Query Monitor Panel under the tab Logs.

use App\Util\QueryMonitorUtil;
$a = 1;
// Simple assertion
QueryMonitorUtil::assert($a === 1);
// Assertion with description
QueryMonitorUtil::assert($a === 1, '$a should be equal to 1');
// Assertion with description and given value
QueryMonitorUtil::assert($a === 1, '$a should be equal to 1', $a);

Check out the documentation site of Query Monitor.