{"id":575286,"date":"2015-03-11T09:32:36","date_gmt":"2015-03-11T09:32:36","guid":{"rendered":"http:\/\/wpml.org\/?post_type=faq&#038;p=575286"},"modified":"2024-08-01T07:29:19","modified_gmt":"2024-08-01T07:29:19","slug":"how-to-debug-performance-problems","status":"publish","type":"faq","link":"https:\/\/wpml.org\/zh-hans\/faq\/how-to-debug-performance-problems\/","title":{"rendered":"How can I debug performance problems?"},"content":{"rendered":"<p class=\"lead\" style=\"text-align: left;\">You can debug performance problems by analyzing your database queries using a plugin like Debug Bar and its Sort Queries add-on.<\/p>\n<h2>What is the Debug Bar plugin?<\/h2>\n<p>The <a href=\"https:\/\/wordpress.org\/plugins\/debug-bar\/\" target=\"_blank\" rel=\"noopener\">Debug Bar <\/a>and <a href=\"https:\/\/github.com\/5um17\/debug-bar-sort-queries\" target=\"_blank\" rel=\"noopener\">Sort Queries add-on<\/a> lets you see a detailed breakdown of the queries running on every page of your site. By analyzing these queries, you can identify which pages slow down your site.<\/p>\n<h2>How can I install the Debug Bar plugin?<\/h2>\n<p>You can install the <strong>Debug Bar<\/strong> plugin via the <strong>Plugins <\/strong>page in your WordPress admin.<\/p>\n<figure id=\"attachment_11432687\" aria-describedby=\"caption-attachment-11432687\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1.png\"><img decoding=\"async\" class=\"size-large wp-image-11432687\" src=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1-1024x543.png\" alt=\"\" width=\"1024\" height=\"543\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1-1024x543.png 1024w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1-300x159.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1-150x80.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1-768x407.png 768w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-install-debug-bar-1.png 1464w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-11432687\" class=\"wp-caption-text\">Installing the Debug Bar plugin<\/figcaption><\/figure>\n<p>To install the Sort Queries add-on, <a href=\"https:\/\/github.com\/5um17\/debug-bar-sort-queries\/archive\/refs\/heads\/main.zip\">download its file<\/a> and upload it to your site.<\/p>\n<h2>Disable Xdebug<\/h2>\n<p>If you&#8217;re using Xdebug, make sure to disable it before you start with performance testing. Xdebug will cause significant load on your server and alter the results.<\/p>\n<p>To disable Xdebug, remove the directive below from your <strong>php.ini<\/strong> file or <strong>conf.d\/xdebug.ini<\/strong>\u00a0file:<\/p>\n<p><code>zend_extension=xdebug.so<\/code><\/p>\n<p>This is how the <strong>phpinfo<\/strong> file should look like when Xdebug is not running:<\/p>\n<figure id=\"attachment_763401\" aria-describedby=\"caption-attachment-763401\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/phpinfo-no-xdebug.png\"><img decoding=\"async\" class=\"wp-image-763401 size-large\" src=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/phpinfo-no-xdebug-1024x109.png\" alt=\"phpinfo when Xdebug is not running (good for performance benchmarking)\" width=\"1024\" height=\"109\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/phpinfo-no-xdebug-1024x109.png 1024w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/phpinfo-no-xdebug-150x16.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/phpinfo-no-xdebug-300x32.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/phpinfo-no-xdebug.png 1124w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-763401\" class=\"wp-caption-text\">phpinfo when Xdebug is not running (good for performance benchmarking)<\/figcaption><\/figure>\n<p>As soon as this does not contain any reference to Xdebug, you can be sure it\u2019s turned off.<br \/>\nWhether or not other sections of this <strong>phpinfo<\/strong> file contain references to Xdebug is not important, so long as it is not shown as a loaded extension at the top.<\/p>\n<h2>How can I configure the Debug Bar?<\/h2>\n<p>The Debug Bar has a couple of debugging options:<\/p>\n<ul>\n<li><code>WP_DEBUG<\/code> \u2013 to identify problems in your code and track PHP Warnings and Notices<\/li>\n<li><code>SAVEQUERIES<\/code> \u2013 to identify any performance issues on your site and to track and display MYSQL queries.<\/li>\n<\/ul>\n<p>To enable these options:<\/p>\n<ol>\n<li>Open your <strong>wp-config.php <\/strong>file.<\/li>\n<li>Scroll down to the line that says <code>\/* That\u2019s all, stop editing! Happy blogging. *\/<\/code>.<\/li>\n<li>Enter the following code:<\/li>\n<\/ol>\n<p><code>define( 'WP_DEBUG', true );<br \/>\ndefine( 'SAVEQUERIES', true );<\/code><\/p>\n<h2>How to debug a page?<\/h2>\n<p>While logged in as admin, visit any page you feel is causing your site to run slowly. Then, from the top admin bar click on <strong>Debug \u2192 Queries<\/strong>.<\/p>\n<figure id=\"attachment_11432717\" aria-describedby=\"caption-attachment-11432717\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1.png\"><img decoding=\"async\" class=\"size-large wp-image-11432717\" src=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1-1024x472.png\" alt=\"\" width=\"1024\" height=\"472\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1-1024x472.png 1024w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1-300x138.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1-150x69.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1-768x354.png 768w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1-1536x707.png 1536w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-debug-queries-1.png 1954w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-11432717\" class=\"wp-caption-text\">Accessing Debug Queries from the top admin bar<\/figcaption><\/figure>\n<p>A screen with the debug information will open.<\/p>\n<p><a href=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-11432767\" src=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-1024x589.png\" alt=\"\" width=\"1024\" height=\"589\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-1024x589.png 1024w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-300x172.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-150x86.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-768x441.png 768w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-1536x883.png 1536w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-queries-screen-1-2048x1177.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>To debug your page, look for:<\/p>\n<ul>\n<li><strong>Slow queries<\/strong> \u2013 a query with an execution time of 50-60 milliseconds.<\/li>\n<li><strong>Repeating queries <\/strong>\u2013 multiple queries that take a long time to complete.<\/li>\n<\/ul>\n<p>To see which plugin or theme a query is coming from, look at the call stack in the second line of each query. In the example below, the query is coming from WPML:<\/p>\n<p><a href=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1.png\"><img decoding=\"async\" class=\"aligncenter size-large wp-image-11432811\" src=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1-1024x531.png\" alt=\"\" width=\"1024\" height=\"531\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1-1024x531.png 1024w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1-300x156.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1-150x78.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1-768x398.png 768w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1-1536x797.png 1536w, https:\/\/wpml.org\/wp-content\/uploads\/2015\/03\/wpml-debug-bar-wpml-query-time-1.png 1932w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>If you identify queries related to WPML or its add-on plugins, write down:<\/p>\n<ul>\n<li>The SQL query<\/li>\n<li>The call stack in the next line of query<\/li>\n<li>The query execution time<\/li>\n<\/ul>\n<p>When opening a support ticket, provide this data to your supporter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can debug performance issues using a plugin like Debug Bar, which provides a detailed breakdown of database queries to help pinpoint slow pages and bottlenecks, visible only to admins.<\/p>\n","protected":false},"author":2,"featured_media":0,"menu_order":30,"template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"ep_exclude_from_search":false,"footnotes":""},"faq-category":[26133],"class_list":["post-575286","faq","type-faq","status-publish","hentry","faq-tags-performance","faq-category-troubleshooting"],"_links":{"self":[{"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/faq\/575286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/faq"}],"about":[{"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/types\/faq"}],"author":[{"embeddable":true,"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":7,"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/faq\/575286\/revisions"}],"predecessor-version":[{"id":16027944,"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/faq\/575286\/revisions\/16027944"}],"wp:attachment":[{"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/media?parent=575286"}],"wp:term":[{"taxonomy":"faq-category","embeddable":true,"href":"https:\/\/wpml.org\/zh-hans\/wp-json\/wp\/v2\/faq-category?post=575286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}