So, you've got your website and it's working... fairly normal. However, you notice some hiccups and a few pages are loading (very) slow. There is a chance that one or more plugins or themes are causing problems. Either because they are incompatible with other plugins/themes or because they contain programming errors. There are multiple ways to go about resolving issues that are caused by plugins and themes. But the important thing is that you know which plugins or theme causes issues. One of the ways to find out is using the plugin called Query Monitor. This guide will show you how to install and use the plugin. 

Two important notes:

  • Query Monitor is a somewhat advanced piece of software. This support article is written for those who either already know a thing or two about the WordPress internal workings or those who are willing to spend time learning and looking around to get more knowledge.
  • Query Monitor is in itself pretty complicated and it will require additional resources to run. Only install and activate it at moments you want to use it and keep it uninstalled when not.

What does Query Monitor do?

Query Monitor, as the name suggests, monitors any queries that your pages generates and feeds them back to you. It doesn't just do this for queries, but also for load times and resources. It will also show any resource loading errors (404 errors and such) that your site encounters.

What do you use it for?

Some example problems for which you might find answers by using the query monitor plugin are:

  • Slow page loading
  • Memory limit errors
  • Timeout errors
  • General performance boosting (advanced)

How to set up Query Monitor

Like any plugin from the Wordpress repository really. But it requires some additional configuration. Log into your site (as administrator), go to the plugins page and click the "Add Plugin" button.

Search for the "query monitor" plugin and install it.

Now, for the additional configuration. You'll need to edit your wp-config.php file via sFTP or SSH. Search for the following line:

define('SAVEQUERIES', false);

Now change this boolean to "true" instead of "false". If this line does not yet exist, you can add it to the file. Do this before the line:

/* That's all, stop editing! Happy blogging. */

The query monitor plugin is now installed.

Testing and interpreting results

For every page you now visit you'll see an addition in the admin bar on the top of your screen:

When clicking this piece of the bar the page will scroll down to the Query Monitor data. This data is added to the bottom of every page. This is where you will find all information.

Breakdown of the useful sections

On the top of the Query Results you will find a brief rundown of memory and time usage. The numbers will be explained in detail down the line.

  1. The time the page took to load. This can/may not exceed 120 seconds on our servers. The higher this number is the more inefficient your site is. If this exceeds 10 seconds you might want to look for ways to optimize your site.
  2. The highest peak of memory usage during this request. This can not exceed 128 MB on our shared servers or 256 MB on our (unmodified) VPS's.
  3. The time it took to receive all needed data from the database.
  4. The count of total queries done on the database to get all the needed information to build the page.
  5. The amount of PHP object data that was fetched from cache. This value will not be used in this guide.

Now we get to the queries used on the page. Query Monitor will give you a table (that can be sorted on loading time in the right column) with all queries done.

The screenshot above shows a simple site with a low amount of queries. It is sorted on query time by clicking on the down arrow in the top right cell. You can use this table to look for large queries that take a long time. It will also show you which component (theme, plugin, core) was responsible for the query.  Play around with the filtering settings to find the information you're looking for.

Next, you will find a summary of the previous table:

This summary will show total loading times and queries grouped by caller and component.

The rest of the Query Monitor results will show information about loaded stylesheets, scripts, and more PHP information. 

Follow-up actions

So what to do with this information? That depends on your initial problem. Following are a few example problems and a way to go about solving them.

One page on my otherwise blazing fast website takes 5+ seconds to load

Well, open up the Query Monitor on this page. Take a look at the summary at the beginning. How long is the page load time and how long is the database query time? If the database query time takes up most of the overall loading time you should check the query table and sort it to show the longest loading queries at the top. If the Component of the heaviest queries is a plugin or theme, try disabling that component to see if the page starts loading faster. If so, you found your problem.

You find memory exhaustion errors in the error log

This usually indicates that a plugin or multiple plugins are trying to use too much memory. Large sites (webshops, multisites) are prone to this problem and are best hosted on a VPS, on which there is more memory available. If you don't think your website should show this error you can use Query Monitor to look for plugins of themes which are taking long to load or have multiple queries to the database. The top plugins / themes on that list can be disabled to see if the issue is resolved.

Since the installation of one plugin, your site is loading a bit slower than usual, but you really need the plugin

The Query Monitor plugin will show you errors and warnings if there are issues. See if the recently installed plugin is responsible for some of these errors. If so: Contact the plugin creator to see if there is anything that can be done about that.