Slow SQL queries
Slow SQL queries can crush your WordPress site’s performance. Sometimes, slow queries are a result of poorly-formed SQL that never should have been done that way. And sometimes, slow queries were actually fast queries at one point—but as the site grew older, the query got slower and slower, unable to keep up with the expanding database.
Query Monitor is a plugin that provides a ton of information about the current page. In addition to a whole bunch of information about the internal workings of WordPress, it gives a detailed breakdown of:
- How many queries happened on this request
- Which queries on the page took the longest
- Which functions spent the most time on SQL queries
- Whether those queries came from plugins, themes or the WordPress core
Too many queries
If a page of your site takes forever to load, than you should first check how many queries are happening for the page request. To do so:
- Let the page load, while you have Query Monitor activated.
- Roll over to the plugins button on the top bar and click Queries by component.
- Check to see if a plugin makes too many queries. In an actual scenario, at one of my websites, the WPML plugin was making 1200 queries! Seems that I had a really old version of the plugin that had query issues. By updating the plugin, the queries went to 30 and improved my site’s performance drastically.
Debug Bar places a new option on your admin bar labeled “Debug” which gives you troubleshooting information on any page on your site. You’ll be able to track PHP errors, SQL queries made on your page, calls to WP Query, info about your HTTP Request and Rewrite Info, and chunks of your Object Cache.
This plugin is for developers, and not meant for a production site. It’s perfect for testing your site locally or on a staging server, but if you weren’t following the list above, this plugin probably isn’t for you.
Before you even install and activate the plugin, you’ll want to make sure you set up your WordPress configuration correctly in order to enable all of Debug Bar’s functionality. In your wp-config.php file, find where it says
and replace it with
define('WP_DEBUG', true); define('WP_DEBUG_DISPLAY', false); define('SCRIPT_DEBUG', true); define('SAVEQUERIES', true);
Once you have added these lines to your wp-config.php, save it, then install and activate Debug Bar. You’ll immediately see a new button added to the top right of your admin bar, labeled “Debug.”
Next, install the Debug Bar Slow Actions plugin. It will let you easily find out which actions and filters are the slowest during a page load.
Visit any page on your site and click this button and a modal box will appear with a list of information on the page that you are on.
At the top global information for your site and server. Your server type, PHP and MySQL version, and the amount of Memory your WordPress install is using.
Notices / Warnings will display any PHP errors or notifications on the page. If there are any, then the Debug button will be orange. Otherwise, you will not see this tab. This will only work if WP_DEBUG is set to true.
Make sure you have no notices or warnings in your page.
Make sure you have deprecated functions in your page.
Debug Bar Slow Actions
If a typical WordPress page load takes more than one second, chances are there’s something terribly wrong with your site, a theme or a plugin is probably doing something it shouldn’t. Obviously you don’t have time to review every single line in your codebase, so Debug Bar Slow Actions might help you out.
It adds a new panel with a list of the top 100 slowest actions (and filters) during the current page request.