What is the
wp profile Command in WP-CLI?
wp profile command is designed for finding where and what is slowing a site down. As with any performance benchmarking, multiple runs will need to be used. Start by running the common commands for
wp profile multiple times. This will help you find what is causing WordPress to load slowly on a site.
This command will output a number of options in the table. They are broken down as:
bootstrapis where WordPress is setting itself up, loading plugins and the main theme, and firing the init hook.
main_queryis how WordPress transforms the request (e.g. /2016/10/21/moms-birthday/) into the primary WP_Query.
templateis where WordPress determines which theme template to render based on the main query, and renders it.
This command will load WordPress, as if a user requested it in a browser.
This command will show the results for only when WordPress is loading.
The spotlight option will show you where those hooks are being used.
In this example command a specific page on the MainWP site is simulated loading in a user’s browser, then it will display which plugins and theme files are being loaded on it. You can use this command to load a specific URL page and then compare between those pages.
In this example command, wp profile hook will profile the hooks being used by WordPress, then will simulate skipping a specific plugin, which might be causing performance issues on a site.
You can compare the results (with/without specific plugins active), but without having to use WP-CLI to deactivate a plugin.
This would be the command that would need to be run to deactivate a plugin to be able to run the spotlight on a specific URL, but using the
--skip-plugin option, you do not have to actually deactivate a plugin for it to be not included in the results.
Manage all your WordPress sites with the MainWP Dashboard
WordPress Management for Professionals
Are you ready to go Pro?
All MainWP Pro Extensions are available through one of our convenient bundled packages.
This command will load the plugins which are needed on the site URL being profiled, then it will show which fields are causing the performance issue. With minor digging, you will be able to find which exact plugins are causing issues on the site with regards to performance. So by finding the plugins causing load issues on the site page, you will disable those plugins from loading on specific pages or changing those plugins with plugins which are more performance optimized.
All of the wp profile commands mentioned in the post are in this Gist.
wp profile command is similar to using New Relic, but without having to set up a New Relic APM account, installing a New Relic WordPress plugin, or having to login to New Relic and drill through the results to find what plugin or database query might be causing performance issues. By using WP-CLI more and more, it will become second nature and will improve your site maintenance.