Query Monitor
What Is Query Monitor
Section titled “What Is 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:
Environments
Section titled “Environments”| Name | Available |
|---|---|
| development | ✅ |
| staging | ✅ |
| production | ❌ |
You can change these settings in the environments folder located here: config/environments.
Key Features
Section titled “Key Features”Database Queries
Section titled “Database Queries”- 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.
PHP Errors
Section titled “PHP Errors”- Error Logging: Captures and displays PHP errors, warnings, and notices.
- Error Context: Provides context about where the errors occurred in the code.
Hooks and Actions
Section titled “Hooks and Actions”- 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.
HTTP Requests
Section titled “HTTP Requests”- External Requests: Tracks outgoing HTTP requests, including API calls, and displays their duration and status.
Scripts and Styles
Section titled “Scripts and Styles”- Enqueued Files: Lists all enqueued scripts and stylesheets, along with their dependencies and load order.
Environment Information
Section titled “Environment Information”- Server Details: Provides details about the server environment, including PHP and MySQL versions.
- WordPress Configuration: Shows information about the WordPress configuration and settings.
User Capabilities
Section titled “User Capabilities”- Current User: Displays the capabilities and roles of the current user.
Conditional Tags
Section titled “Conditional Tags”- Page Context: Lists the WordPress conditional tags that are true for the current request.
Ajax and REST API
Section titled “Ajax and REST API”- 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.
Lumber Mill Specific Utilities
Section titled “Lumber Mill Specific Utilities”Profiling
Section titled “Profiling”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') }}Assertions
Section titled “Assertions”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 assertionQueryMonitorUtil::assert($a === 1);
// Assertion with descriptionQueryMonitorUtil::assert($a === 1, '$a should be equal to 1');
// Assertion with description and given valueQueryMonitorUtil::assert($a === 1, '$a should be equal to 1', $a);Learn More
Section titled “Learn More”Check out the documentation site of Query Monitor.

