<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Engineer &#187; Debug Queries</title>
	<atom:link href="http://wpengineer.com/tag/debug-queries/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>debugConsole with WordPress</title>
		<link>http://wpengineer.com/2068/debugconsole-with-wordpress/</link>
		<comments>http://wpengineer.com/2068/debugconsole-with-wordpress/#comments</comments>
		<pubDate>Wed, 20 Oct 2010 10:47:42 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Debug Queries]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2068</guid>
		<description><![CDATA[For debugging inside of WordPress there are different approaches and preferences. I like xDebug and in some cases I use FirePHP. Now there is another possibility which I had to test at least once - debugConsole - I like it. The debugConsole is a tool for debugging and tracing PHP5 applications on productive servers without [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://wpengineer.com/wp-content/uploads/debugconsole-backend.png"><img src="http://wpengineer.com/wp-content/uploads/debugconsole-backend-230x300.png" alt="" title="debugconsole-backend" width="230" height="300" class="alignright size-medium wp-image-2069" /></a><br />
For debugging inside of WordPress there are different approaches and preferences. I like <a href="http://www.xdebug.org/">xDebug</a> and in some cases I use <a href="http://www.firephp.org/">FirePHP</a>. Now there is another possibility which I had to test at least once - <a href="http://www.debugconsole.de/">debugConsole</a> - I like it.</p>
<blockquote><p>The debugConsole is a tool for debugging and tracing PHP5 applications on productive servers without compromising the live-traffic. </p></blockquote>
<p><span id="more-2068"></span></p>
<h4>The features</h4>
<ul>
<li>access features</li>
<li>variable inspector</li>
<li>variable watches</li>
<li>replace PHP's errorhandling</li>
<li>timer clock</li>
<li>checkpoint management</li>
<li>and other features
<ul>
<li>filter events</li>
<li>log console output into logfiles additionally to or instead of the popup</li>
<li>configure dimensions and design of console window</li>
<li>color-coded events for quicker overview</li>
</ul>
</li>
</ul>
<p>So I created a little Plugin to play and test the console.<br />
Currently I have only created a demo Plugin which shows the function. It won't be maintained, but can be downloaded here. As a small start and quick look at the possibilities I used the examples of the author of the <a href="http://www.debugconsole.de/">debugConsole</a>.</p>
<p><a href="http://wpengineer.com/wp-content/uploads/debugconsole-frontend.png"><img src="http://wpengineer.com/wp-content/uploads/debugconsole-frontend-300x117.png" alt="" title="debugconsole-frontend" width="300" height="117" class="aligncenter size-medium wp-image-2070" /></a></p>
<p>The Plugin has the following source code and you can add to any URL of the WP-installation the string <code>?debug=true</code>, so that the popup called with the information of the console. Currently this is possible for frontend and backend.</p>
<pre>
&lt;?php
/*
Plugin Name: debugConsole
Plugin URI: http://bueltge.de/
Text Domain: debugconsole
Domain Path: /languages
Description: The &lt;a href=&quot;http://www.debugconsole.de/&quot;&gt;debugConsole&lt;/a&gt;
is a tool for debugging and tracing PHP5 applications on productive servers
without compromising the live-traffic. Add &lt;code&gt;?debug=true&lt;/code&gt; to the URL for see
the Popup-Window with debugConsole
Author: Frank B&uuml;ltge
Version: 0.1
Author URI: http://bueltge.de/
Donate URI: http://bueltge.de/wunschliste/
License: Apache License
Last change: 14.10.2010 11:30:51
*/ 

/**
License:
==============================================================================
Copyright 2010 Frank Bueltge  (email : frank@bueltge.de)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Requirements:
==============================================================================
This plugin requires WordPress &gt;= 2.7 and tested with PHP Interpreter &gt;= 5.2.9
*/

/* PHP5 required */
if (version_compare(PHP_VERSION, &#039;5.0.0&#039;) &lt; 0) {
	die(&#039;The debugConsole requires PHP 5.x.x or greater.&#039;);
}

/* load debugConsole functionality */
require_once &#039;debugconsole-1.3.0/debugConsole.php&#039;;

// add ?debug=true to the URL
if ( isset($_GET&#091;&#039;debug&#039;&#093;) &amp;&amp; $_GET&#091;&#039;debug&#039;&#093; == &#039;true&#039;) {
	add_action( &#039;wp_footer&#039;, &#039;wp_debug_console&#039; );
	add_action( &#039;admin_footer&#039;, &#039;wp_debug_console&#039; );
}

function wp_debug_console() {

	/**
	* debugConsole demonstration
	*
	* This script demonstrates each feature of the debugConsole. The
	* debugConsole is a PHP5 class using JavaScripts to show debug
	* information in a popup window. The popup has IP-based access
	* control. Configurate everything in debugConsole.config.php.
	* Additionally, PHP&#039;s default errorhandler is replaced.
	*
	* @author Andreas Demmer &lt;mail@andreas-demmer.de&gt;
	* @version 1.0.1
	* @package debugConsole_1.2.0
	*/

	/*
	Now you got an extended commandset:

	dc_watch()           watch variable changes in console
	dc_dump()            var_dump variables in console
	dc_here()            mark checkpoints in console
	dc_start_timer()     measure a timespan
	dc_stop_timer()      output timespan in console
	*/

	/* test watches */
	dc_watch(&#039;foo&#039;);

	declare (ticks = 1) {
		$foo = &#039;1&#039;;
		$foo++;

		/* test checkpoints */
		dc_here(&#039;The interpreter passed through here!&#039;);

		/* test timer clock */
		$myTimer = dc_start_timer(&#039;Measure an one second sleep:&#039;);
		sleep(1);
		dc_stop_timer($myTimer);

		/* test variable debugging */
		$bar = 42.0;
		dc_dump($bar, &#039;$bar tells us the meaning of life:&#039;);

		$foobar = array (
				&#039;foo&#039; =&gt; $foo,
				&#039;bar&#039; =&gt; $bar
		);

		dc_dump($foobar, &#039;$foobar is a neat array!&#039;);

		/* test errorhandling */
		echo $notSet;
		fopen(&#039;not existing!&#039;, &#039;r&#039;);
	}

}
?&gt;
</pre>
<p>Download as zip-file: <a href="http://wpengineer.com/wp-content/uploads/debugConsole.zip">debugConsole.zip</a> - 131 kByte<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2068/debugconsole-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Analyze WordPress Performance &#8211; Plugin!</title>
		<link>http://wpengineer.com/1176/analyze-wordpress-performance-plugin/</link>
		<comments>http://wpengineer.com/1176/analyze-wordpress-performance-plugin/#comments</comments>
		<pubDate>Tue, 05 May 2009 12:54:19 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Plugins]]></category>
		<category><![CDATA[Debug Queries]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1176</guid>
		<description><![CDATA[Recently Joost mentioned in a post on yoast.com, how he used my Plugin "Debug Queries" to optimize his WordPress database performance (BTW, thanks for the patch). Performance of WordPress can be quickly and easily negative effected by using some Plugins. You don't have to be an expert to know, that more function will provide more [...]]]></description>
			<content:encoded><![CDATA[<p>Recently Joost mentioned in a post on <a href="http://yoast.com/wordpress-performance-optimization/">yoast.com</a>, how he used my Plugin "<a href="http://wordpress.org/extend/plugins/debug-queries/">Debug Queries</a>" to optimize his WordPress database performance (BTW, thanks for the patch). </p>
<p>Performance of WordPress can be quickly and easily negative effected by using some Plugins. You don't have to be an expert to know, that more function will provide more load. However, provides the simplicity of creating a Plugin for WordPress, which have made it so popular and I very much appreciate, a problem - You don't have to be a professional developer to create a Plugin, but an optimized syntax lead to a much improved performance of a WordPress installation.</p>
<h3>But the real problem: How to find the weak point in your blog?</h3>
<p>You can use some tools to analyze performance, for example the Add-on <a href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a> in Firefox, especially with <a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow</a>. This helps to find scripts which slowing down your blog and vulnerabilities in a code. Also makes sense that "many" scripts, which get installed with some Plugins, should not be load by wp_head but in wp_footer. Scripts should be placed in the footer to improve the performance.</p>
<p>However, the analysis via disabling / enabling all Plugins is a hassle. It would be useful, to examine the different queries and look at what function they refer.</p>
<p>WordPress offers the possibility to display the total number of queries, as well as the time needed. With the following syntax, preferably put in the footer of the page, this is done quickly.</p>
<pre lang="php">&lt;?php echo $wpdb-&gt;num_queries; ?&gt;q, &lt;?php timer_stop(1); ?&gt;s</pre>
<p>But the variable <code>$wpdb</code> offers more to look into the <code>/wp-includes/wp-db.php</code>.</p>
<pre lang="php">if (!defined(&#039;SAVEQUERIES&#039;))
define(&#039;SAVEQUERIES&#039;, false);

class wpdb {

var $show_errors = true;
var $num_queries = 0;
var $last_query;
var $col_info;
var $queries;
var $prefix = &#039;&#039;;

// Our tables
var $posts;
var $users;
var $categories;
var $post2cat;
var $comments;
var $links;
var $options;
var $postmeta;
var $usermeta;
var $terms;
var $term_taxonomy;
var $term_relationships;
var $tables = array(&#039;users&#039;, &#039;usermeta&#039;, &#039;posts&#039;, &#039;categories&#039;, &#039;post2cat&#039;, &#039;comments&#039;, &#039;links&#039;, &#039;link2cat&#039;, &#039;options&#039;, &#039;postmeta&#039;, &#039;terms&#039;, &#039;term_taxonomy&#039;, &#039;term_relationships&#039;);
var $charset;
var $collate;</pre>
<p>You will notice the constant <code>SAVEQUERIES</code> which is not defined in <code>wp-config.php</code>. Setting this constant to TRUE, it leaves the door open for other possibilities.<br />
But I don't want to get in too much details, because it would be too much for just one post. Who has an interest can find a whole range of information in the said file.</p>
<p>My goal was not to get the total number of queries in the blog as a result, but the individual queries including their syntax, because then I can find the problem explicitly in the code.</p>
<p>To ensure that this will work easily and quickly on every blog, I created a <a href="http://wordpress.org/extend/plugins/debug-queries/">Plugin</a> and just have to enable it,  if I want to get an analysis. In addition, the analysis will only start and the result displayed when an administrator is logged in.</p>
<p>The result may look like this for example:</p>
<p><a href="http://wordpress.org/extend/plugins/debug-queries/screenshot-1.png"><img src="http://wpengineer.com/wp-content/uploads/debug_queries.png" alt="debug_queries" title="debug_queries" width="450" height="202" class="aligncenter size-full wp-image-1202" /></a></p>
<pre lang="php">16. Time: 0.000431060791016
Query: SELECT object_id, term_taxonomy_id FROM fb122_term_relationships INNER JOIN fb122_posts ON object_id = ID WHERE term_taxonomy_id IN (6,5,1) AND post_type = &#039;post&#039; AND post_status = &#039;publish&#039;
Call from: wp-includes\taxonomy.php(2093): wpdb-&gt;get_results()

17. Time: 0.00243401527405
Query: SELECT t.*, tt.* FROM fb122_terms AS t INNER JOIN fb122_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN (&#039;link_category&#039;) AND tt.count &gt; 0 ORDER BY t.name ASC
Call from: wp-includes\taxonomy.php(777): wpdb-&gt;get_results()

18. Time: 0.00080418586731
Query: SELECT * , IF (DATE_ADD(link_updated, INTERVAL 120 MINUTE) &gt;= NOW(), 1,0) as recently_updated FROM fb122_links INNER JOIN fb122_term_relationships AS tr ON (fb122_links.link_id = tr.object_id) INNER JOIN fb122_term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id WHERE 1=1 AND link_visible = &#039;Y&#039; AND ( tt.term_id = 2 ) AND taxonomy = &#039;link_category&#039; ORDER BY link_name ASC
Call from: wp-includes\bookmark.php(255): wpdb-&gt;get_results()

* Total query time: 0.02111s for 18 queries.
* Page generated in 0.36373s, 94.20% PHP, 5.80% MySQL
</pre>
<p>The work certainly is not necessarily pleasant, but I can find the real problems in the database query and maybe improve the corresponding query or deactivate it. The Plugin uses some more information than the above tutorial, so it is understandable and more informational.</p>
<h3>Debug Queries (plugin)</h3>
<p>After activating the plugin, the individual queries will be written in the footer of the page, as an HTML comment. So you must analyze the source code to retrieve the values. The values are analyzed and displayed only when an administrator is logged in.</p>
<p><a href="http://wordpress.org/extend/plugins/debug-queries/">You can Download Debug Queries here</a>!</p>
<h3>Further Plugins to analyze and improve your WordPress database</h3>
<ul>
<li><a href="http://www.tierra-innovation.com/blog/?p=340">WPDB Profiling</a></li>
<li><a href="http://wordpress.org/extend/plugins/clean-options/">Clean Options</a></li>
<li><a href="http://wordpress.org/extend/plugins/wptuner/">WP Tuner</a></li>
<li><a href="http://wordpress.org/extend/plugins/sqlmon/">SQL Monitor</a></li>
</ul>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1176/analyze-wordpress-performance-plugin/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

