<?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>Sivel.net &#187; HowTo</title>
	<atom:link href="http://sivel.net/category/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://sivel.net</link>
	<description>Throwing Hot Coals</description>
	<lastBuildDate>Tue, 17 Jan 2012 22:32:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>WordPress Caching Comparisons Part 2</title>
		<link>http://sivel.net/2011/12/wordpress-caching-comparisons-part-2/</link>
		<comments>http://sivel.net/2011/12/wordpress-caching-comparisons-part-2/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 16:12:04 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=1078</guid>
		<description><![CDATA[This post has been on my mind for quite some time now, ever since I wrote Part 1 over 1 year ago. Part 1 only really addressed opcode and Object caching and didn&#8217;t really touch page caching. In this post &#8230; <a href="http://sivel.net/2011/12/wordpress-caching-comparisons-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This post has been on my mind for quite some time now, ever since I wrote Part 1 over 1 year ago.</p>
<p>Part 1 only really addressed opcode <a class="simple-footnote" title="opcode: A technique of optimizing the PHP code and caching the bytecode compiled version of the code, to reduce the compilation time incurred during PHP code execution" id="return-note-1078-1" href="#note-1078-1"><sup>1</sup></a> and Object caching <a class="simple-footnote" title="Object Caching: An in memory key-value storage for arbitrary data, to reduce processing, and storage of external calls to speed up retrieval and display of information" id="return-note-1078-2" href="#note-1078-2"><sup>2</sup></a> and didn&#8217;t really touch page caching <a class="simple-footnote" title="Page Caching: Full caching of HTML output for web pages" id="return-note-1078-3" href="#note-1078-3"><sup>3</sup></a>. In this post I have revisited all tests and added in comparisons of using both the <a href="http://wordpress.org/extend/plugins/apc/">APC Object Cache</a> + <a href="http://wordpress.org/extend/plugins/batcache/">Batcache</a> plugins as well as using the <a href="http://wordpress.org/extend/plugins/w3-total-cache/">W3 Total Cache</a> plugin.</p>
<h3>Tests</h3>
<ul>
<li>No opcode, no caching</li>
<li>APC opcode, no caching</li>
<li>APC opcode, APC object caching plugin</li>
<li>APC opcode, W3 Total Cache APC object caching</li>
<li>APC opcode, APC object caching plugin, Batcache page caching</li>
<li>APC opcode, W3 Total Cache APC object and page caching</li>
</ul>
<h3>Comparison Stats</h3>
<ul>
<li>PHP generation time <a class="simple-footnote" title="PHP generation time: The amount of time taken to compile and execute the PHP code into the resulting HTML" id="return-note-1078-4" href="#note-1078-4"><sup>4</sup></a></li>
<li>Number of include/include_once/require/require_once calls <a class="simple-footnote" title="Include/Require Count: The number of calls to the PHP include, include_once, require and require_once functions, which are used to load a separate file" id="return-note-1078-5" href="#note-1078-5"><sup>5</sup></a></li>
<li>Number of stat() calls per dtruss/strace <a class="simple-footnote" title="stat() call count: The number of unix system calls that return information about files, directories and other filesystem related objects." id="return-note-1078-6" href="#note-1078-6"><sup>6</sup></a></li>
<li>cURL time to start transfer <a class="simple-footnote" title="Start Transfer Time: The amount of time between the request from the client to the server, and when the server begins returning data to the client" id="return-note-1078-7" href="#note-1078-7"><sup>7</sup></a></li>
<li>Apache Bench (ab) tests for concurrency <a class="simple-footnote" title="Concurrency: The number of concurrent client requests to the server" id="return-note-1078-8" href="#note-1078-8"><sup>8</sup></a> and requests per second</li>
</ul>
<p>For the above stats gathering, with PHP generation time and cURL time to start transfer, 102 sets were collected, the first 2 were dropped due to cache priming, the remaining 100 were used, and averaged. With the Apache Bench tests, 12 sets were used, dropping the highest and lowest value, and averaging across the remaining 10. Include and stat() counts were gathered over 5 sets not requiring averaging as they were the same between runs.</p>
<p>To find the optimal concurrency and req/s for Apache Bench, I performed manual testing, visually inspecting the results until I reached what I classified as a &#8220;sweet spot&#8221;. Using the &#8220;sweet spot&#8221; stats, I performed additional sets to gather the averages for requests per second.</p>
<h3>The Setup</h3>
<ul>
<li>256MB Rackspace Cloud Server</li>
<li>Ubuntu 11.04 amd64</li>
<li>Apache 2.2.17 &#8211; Default Ubuntu Install, no modifications, default document root located at /var/www</li>
<li>PHP 5.3.5 (mod_php) &#8211; Default Ubuntu Install, no modifications</li>
<li>PHP APC 3.1.3p1 &#8211; Default Ubuntu Install, no modifications</li>
<li>MySQL 5.1.54 &#8211; Default Ubuntu Install, no modifications</li>
<li>WordPress 3.3-beta4-r19470 &#8211; Default Install, requests made to the &#8220;home&#8221; page</li>
<li>APC Object Cache trunk version</li>
<li>Batcache trunk version</li>
<li>W3 Total Cache 0.9.2.4</li>
</ul>
<p>I have not compared static file caching yet and hope to compare W3 Total Cache and WP Super Cache in the future.  In this comparison I am mainly focusing on opcode, object caching and page caching.</p>
<p>I am going to try to keep this comparison about the stats only, and not make this a critique or review of the plugin, although in some cases this will not be possible.</p>
<h3>Test Data</h3>
<p><strong>No opcode and no caching:</strong><br />
PHP Generation Time: 0.13787 seconds<br />
Number of includes: 80<br />
Number of stat calls: 266<br />
cURL time to start transfer: 0.15463 seconds<br />
Apache Bench Concurrency: 15<br />
Apache Bench Requests Per Second: 19.1483 req/s</p>
<p><strong>APC opcode and no caching:</strong><br />
PHP Generation Time: 0.05088 seconds<br />
Number of includes: 80<br />
Number of stat calls: 148<br />
cURL time to start transfer: 0.05673 seconds<br />
Apache Bench Concurrency: 60<br />
Apache Bench Requests Per Second: 68.2636 req/s</p>
<p><strong>APC opcode and APC Object caching:</strong><br />
PHP Generation Time: 0.03407 seconds<br />
Number of includes: 81<br />
Number of stat calls: 148<br />
cURL time to start transfer: 0.03975 seconds<br />
Apache Bench Concurrency: 260<br />
Apache Bench Requests Per Second: 77.7214 req/s</p>
<p><strong>APC opcode and W3TC APC Object caching:</strong><br />
PHP Generation Time: 0.03993 seconds<br />
Number of includes: 102<br />
Number of stat calls: 285<br />
cURL time to start transfer: 0.04591 seconds<br />
Apache Bench Concurrency: 200<br />
Apache Bench Requests Per Second: 67.581 req/s</p>
<p><strong>APC opcode and APC Object and Page caching with Batcache:</strong><br />
PHP Generation Time: N/A<br />
Number of includes: Unable to collect<br />
Number of stat calls: 41<br />
cURL time to start transfer: 0.00316 seconds<br />
Apache Bench Concurrency: 600<br />
Apache Bench Requests Per Second: 147.2156 req/s</p>
<p><strong>APC opcode and W3TC APC Object and Page caching:</strong><br />
PHP Generation Time: N/A<br />
Number of includes: Unable to collect<br />
Number of stat calls: 87<br />
cURL time to start transfer: 0.00625 seconds<br />
Apache Bench Concurrency: 500<br />
Apache Bench Requests Per Second: 147.8425 req/s</p>
<h3>Conclusions</h3>
<p>I can state the following about just enabling APC in PHP, if you do nothing else, you should at least do this:</p>
<ol>
<li>170% PHP generation time improvement by enabling APC opcode caching</li>
<li>172% Time to start transfer improvement by enabling APC opcode caching</li>
<li>300% concurrency improvement by enabling APC opcode caching</li>
<li>256% requests per second improvement by enabling APC opcode caching</li>
</ol>
<p>I see performance improvements using both APC+Batcache and W3 Total Cache. However, in all tests, APC+Batcache seems to outperform W3 Total Cache, in PHP generation time, number of includes, number of filesystem stat() calls, time to start transfer, number of concurrent requests and requests per second with relation to concurrency.</p>
<p>I was able to push APC+Batcache to 700 concurrent requests, but req/s dropped. W3TC capped out at 500 concurrent requests, and would go no further, however 500 requests per second provided the highest req/s for W3TC.</p>
<p>W3TC does provide a lot of additional functionality to help reduce load on the server, such as tweaking client side caching, and using a CDN, where APC+Batcache does not, although there are small unitasking plugins that can add the missing functionality for you such as:</p>
<ul>
<li><a href="http://wordpress.org/extend/plugins/wp-minify/">WP Minify</a></li>
<li><a href="http://wordpress.org/extend/plugins/cdn-tools/">CDN Tools</a></li>
<li><a href="http://wordpress.org/extend/plugins/use-google-libraries/">Use Google Libraries</a></li>
</ul>
<p>APC+Batcache consists of adding 3 new files, and no new directories. The W3TC download consists of 60 new directories and 351 files. The directory listing level for W3TC being as deep as it is, 5 levels deep past the directory for the plugin itself, causes a significant increase in filesystem stat() commands.</p>
<p>Most shared hosting providers as well as many multiserver environments will often host their web roots on NFS, and the more filesystem stat() calls, the worse performance you will see, especially under higher load.</p>
<p>Something else to note, is a lot can be done on the server to also improve performance. You can also use caching applications that logically sit in front of the webserver to cache, instead of using caching plugins, which will also improve performance. There are probably eleventy billion ways to improve performance, so if in doubt, consult an expert to help.</p>
<div class="simple-footnotes"><p class="notes">Notes:</p><ol><li id="note-1078-1">opcode: A technique of optimizing the PHP code and caching the bytecode compiled version of the code, to reduce the compilation time incurred during PHP code execution <a href="#return-note-1078-1">&#8617;</a></li><li id="note-1078-2">Object Caching: An in memory key-value storage for arbitrary data, to reduce processing, and storage of external calls to speed up retrieval and display of information <a href="#return-note-1078-2">&#8617;</a></li><li id="note-1078-3">Page Caching: Full caching of HTML output for web pages <a href="#return-note-1078-3">&#8617;</a></li><li id="note-1078-4">PHP generation time: The amount of time taken to compile and execute the PHP code into the resulting HTML <a href="#return-note-1078-4">&#8617;</a></li><li id="note-1078-5">Include/Require Count: The number of calls to the PHP include, include_once, require and require_once functions, which are used to load a separate file <a href="#return-note-1078-5">&#8617;</a></li><li id="note-1078-6">stat() call count: The number of unix system calls that return information about files, directories and other filesystem related objects. <a href="#return-note-1078-6">&#8617;</a></li><li id="note-1078-7">Start Transfer Time: The amount of time between the request from the client to the server, and when the server begins returning data to the client <a href="#return-note-1078-7">&#8617;</a></li><li id="note-1078-8">Concurrency: The number of concurrent client requests to the server <a href="#return-note-1078-8">&#8617;</a></li></ol></div>]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2011/12/wordpress-caching-comparisons-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress Caching Comparisons Part 1</title>
		<link>http://sivel.net/2010/11/wordpress-caching-comparisons-part-1/</link>
		<comments>http://sivel.net/2010/11/wordpress-caching-comparisons-part-1/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 16:06:56 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=1008</guid>
		<description><![CDATA[For some time now I have been wanting to write an up to date XCache object cache plugin for WordPress. Around 4 years ago I did an opcode caching comparison between APC, XCache and eAccelerator. My results had shown that &#8230; <a href="http://sivel.net/2010/11/wordpress-caching-comparisons-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For some time now I have been wanting to write an up to date XCache object cache plugin for WordPress.  Around 4 years ago I did an opcode caching comparison between APC, XCache and eAccelerator.  My results had shown that at the time that XCache was the fastest of the 3.  Unfortunately I didn&#8217;t think to keep that data around.  As a result of these tests I had standardized the environment I was working on with XCache, and have never thought twice about it.  Since I use XCache for opcode caching everywhere, it seemed like writing such an object cache plugin would be beneficial.  After writing the plugin I figured it best to test performance, comparing it to the Memcached object cache and the APC Object cache.  I tweeted a lot during my initial testing, and got an overwhelming response to write up a post, and here we are&#8230;</p>
<p>I&#8217;ll try to make this comparison comprehensive, but it can be a little difficult to always cover everything.</p>
<p>The test environment:</p>
<ul>
<li>Toshiba T135-S1310</li>
<li>Intel SU4100 64bit Dual-Core 1.3GHz</li>
<li>4GB DDR3 Memory</li>
<li>Ubuntu 10.10 64bit</li>
<li>Apache 2.2.16</li>
<li>PHP 5.3.3</li>
<li>PHP XCache 1.3.0</li>
<li>PHP APC 3.1.3p1</li>
<li>Memcached 1.4.5</li>
<li>Pecl Memcached 3.0.4</li>
<li>MySQL 5.1.49 No caching configured</li>
<li>cURL 7.21.0</li>
<li>WordPress 3.1-alpha (r16527) Default install with Twenty Ten and no plugins other than the one I mention below</li>
</ul>
<p>The times are based off of the standard timer_stop() code often found in the footer.php of themes, in this case added using the wp_footer filter through a mu (must use) plugin:</p>
<pre>
<code>&lt;?php
add_action(&#039;wp_footer&#039;, &#039;print_queries&#039;, 1000);
function print_queries() {
?&gt;
&lt;!-- &lt;?php echo get_num_queries(); ?&gt; queries. &lt;?php timer_stop(1); ?&gt; seconds. --&gt;
&lt;?php
}</code>
</pre>
<p>cURL was used to make the HTTP requests and grab the value from the comment created by the above code:</p>
<pre>
<code>for (( c=1; c&lt;=101; c++ )); do curl -s http://wordpress.trunk/ | grep &#039;&lt;/body&gt;&#039; -B 1 | head -1 | awk -F&quot;queries. &quot; &#039;{print $2}&#039; | awk -F&quot; seconds&quot; &#039;{print $1}&#039;; done;</code>
</pre>
<p>In each data set I gather 101 results and omit result 1 so that we only have results after the initial cache is generated.  The tests are only performed on the home page.</p>
<p>The tests:</p>
<ol>
<li>No Object or Opcode Cache</li>
<li>Memcached Object Cache with no Opcode Cache</li>
<li>Memcached Object Cache with APC Opcode Cache</li>
<li>Memcached Object Cache with XCache Opcode Cache</li>
<li>APC Object and Opcode Cache</li>
<li>APC Opcode Cache with no Object Cache</li>
<li>XCache Object and Opcode Cache</li>
<li>XCache Opcode Cache with no Object Cache</li>
</ol>
<p>I didn&#8217;t evaluate eAccelerator due to the fact that it isn&#8217;t available in the Ubuntu repositories and I did not feel likely compiling&#8230;</p>
<p>The results (in seconds):</p>
<p><iframe width='100%' height='157' frameborder='0' src='https://spreadsheets.google.com/pub?key=0AlRMJ5h6yNYAdGV5UHFmdjNKLTBEOE9IMVktVXcxU1E&#038;hl=en&#038;output=html&#038;widget=true'></iframe></p>
<p>For a larger view of the spreadsheet above or if you cannot see it, take a look <a href="https://spreadsheets.google.com/pub?key=0AlRMJ5h6yNYAdGV5UHFmdjNKLTBEOE9IMVktVXcxU1E&#038;hl=en&#038;output=html">here</a>.</p>
<p>These results are quite interesting and actually shocked me a little bit.  The first thing that I found when developing an up to date XCache Object Cache plugin was that it can&#8217;t handle objects!  So the plugin has to serialize all data when setting, and unserialize when retrieving.  This of course is going to add overhead to every operation.</p>
<p>When I first tested the Memcached Object Cache I was surprised at how little it improved speed.  It took me about an hour to realize that the comparison of just using Memcached was unfair as it didn&#8217;t include any Opcode caching, adding an Opcode cache brings it more in line with what I would expect.</p>
<p>Using an opcode cache improves performance by over 200% on a stock WordPress install without using any object caching.  While APC and XCache provided similar results, my tests still show XCache to be ever so slightly faster as an opcode cache.</p>
<p>Where we see the biggest difference between the 3 of these caches when using APC for both opcode and object caching.</p>
<p>Assuming we are using both Opcode and Object caching here are the results from best to worst:</p>
<ol>
<li>APC</li>
<li>Memcached (With either APC or XCache)</li>
<li>XCache</li>
</ol>
<p>At this point the single largest failure of XCache is it&#8217;s inability to store objects, so I am pretty much planning on dropping XCache on my servers in favor of APC, which will be included with PHP as of PHP 6.  I would likely still see marginal speed improvements using XCache on sites that I am not using XCache for an object cache, but on those that I am I&#8217;ll get much improved performance off of APC or Memcached.</p>
<p>Now why would I want to use APC over Memcached or vice versa?  Well, the one thing that Memcached provides that APC doesn&#8217;t is the ability to share the cache between servers.  In a load balanced multi web server environment, using APC you would be duplicating the cache on all of the servers as APC provides no way to share this data or allow for remote connections.  Memcached however, being a PHP independent daemon can be used for pooling resources and allowing remote connections.  You also can get more bang for your buck with Memcached in a load balanced multi server environment because of it&#8217;s pooling capability.  The pooling capability allows you to dedicate say 128MB of RAM to each memcached instance and when pooled together will give you 128MB x N where N is the number of servers in the pool.  Anyway, I digress&#8230;</p>
<p>In the end, if you have WordPress hosted on a single web server, APC is the way to go.  If you are in a multi web server environment, Memcached is the way to go, but remember to install an Opcode cache as well.  If you are crazy and just want to use more CPU cycles, XCache is the way to go.</p>
<p>Some of you may be thinking &#8220;why would I need an object cache in addition opcode caching, if the results are similar?&#8221;  Well, under higher load an object cache will respond better than MySQL, even with MySQL caching.  In addition, other factors with MySQL can come into play, such as connectivity to the MySQL server.  It may be on another server, with not enough memory, slow disks, with an overloaded network, which decreases performance.  Any time that an update query is run, MySQL will flush the whole cache.  Another benefit, is we are rarely, if ever, going to use the data exactly as it is given to us from the MySQL query.  In the end we are going to process the data before displaying, an object cache allows you to store the processed data, rather than the raw data from the query saving CPU cycles required for the processing.  Individually these items may not consume much time, but added together and in a more efficient delivery system, this can make a huge difference.</p>
<p>Now for any of you who go run out and install Memcached, if you install version 1.4.x make sure you get at least pecl memcached 2.2.6 or 3.0.4.  Memcached made a change that breaks deletes with earlier pecl memcached versions, which adversely affects WordPress.</p>
<p>A few additional things that I have been asked to talk about are using caching with a WordPress Network, output caching with Batcache and query counts.  I promise to get to those, but I just wanted to get this out sooner rather than later.</p>
<p>Yo Dawg! We heard you like caching so we put a cache in your cache, so you can optimize while you optimize&#8230;Sorry couldn&#8217;t resist.</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2010/11/wordpress-caching-comparisons-part-1/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Using MySQL Sockets in the WordPress wp-config.php</title>
		<link>http://sivel.net/2010/06/using-mysql-sockets-in-the-wordpress-wp-config-php/</link>
		<comments>http://sivel.net/2010/06/using-mysql-sockets-in-the-wordpress-wp-config-php/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 15:23:43 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=959</guid>
		<description><![CDATA[Recently I have been getting a lot of questions about how to use a MySQL socket in place of the DB_HOST constant for WordPress in the WordPress IRC channel. Fortunately this is pretty easy, unfortunately if you are using the &#8230; <a href="http://sivel.net/2010/06/using-mysql-sockets-in-the-wordpress-wp-config-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I have been getting a lot of questions about how to use a MySQL socket in place of the DB_HOST constant for WordPress in the <a href="irc://irc.freenode.net/wordpress">WordPress IRC channel</a>.</p>
<p>Fortunately this is pretty easy, unfortunately if you are using the web based installer you cannot specify a socket in the &#8220;Database Host&#8221; field.  However, you can do things the manual way and copy wp-config-sample.php to wp-config.php and go that route.</p>
<p>The first thing you need to do is determine the path to the MySQL socket.  By inspecting my.cnf you would need to look for something that looks like:</p>
<pre><code>socket      = /var/run/mysqld/mysqld.sock</code></pre>
<p>If you don&#8217;t have access to look at my.cnf you can try to run the following MySQL query:</p>
<pre><code>SHOW VARIABLES LIKE &#039;socket&#039;;</code></pre>
<p>Now crack open your wp-config.php file and set DB_HOST to &#8216;:/path/to/mysql.sock&#8217;.  Take careful note of the &#8216;:&#8217; (colon) preceding the path.  In my example the define for the DB_HOST looks like:</p>
<pre><code>define(&#039;DB_HOST&#039;, &#039;:/var/run/mysqld/mysqld.sock&#039;);</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2010/06/using-mysql-sockets-in-the-wordpress-wp-config-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Detect wp_head and wp_footer from a Plugin</title>
		<link>http://sivel.net/2010/04/detect-wp_head-and-wp_footer-from-a-plugin/</link>
		<comments>http://sivel.net/2010/04/detect-wp_head-and-wp_footer-from-a-plugin/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 20:36:45 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=948</guid>
		<description><![CDATA[Normally I start these posts with &#8220;Every so often someone asks a question in the WordPress IRC channel that sparks my interest&#8221;, however today, to my great surprise someone actually caught my attention on the wp-hackers mailing list. For those &#8230; <a href="http://sivel.net/2010/04/detect-wp_head-and-wp_footer-from-a-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Normally I start these posts with &#8220;Every so often someone asks a question in the WordPress IRC channel that sparks my interest&#8221;, however today, to my great surprise someone actually <a href="http://lists.automattic.com/pipermail/wp-hackers/2010-April/031683.html">caught my attention</a> on the <a href="http://lists.automattic.com/mailman/listinfo/wp-hackers">wp-hackers</a> mailing list.</p>
<p>For those of you who didn&#8217;t click through, the question was:</p>
<blockquote><p>
Couldn&#8217;t find this on forums or anywhere else.<br />
What can I test to check if wp_footer was placed on the theme?
</p></blockquote>
<p>Before any replies came in I was already interested and when <a href="http://blog.ftwr.co.uk">Peter Westwood</a> replied with &#8220;The other way to do it is to do a http request based test which a special query arg on which you output a string on wp_footer.&#8221;, I was on the hook.</p>
<p>I spent a few minutes writing up a test plugin, to perform only this functionality and responded back to the list.  It was pretty well accepted and I got a few comments from <a href="http://planetozh.com">Ozh</a> and <a href="http://www.andrewnacin.com/">Andrew Nacin</a> on Twitter.  One of the comments was actually an idea, to extend the checks to make sure that the calls to <code>&lt;?php wp_head(); ?&gt;</code> and <code>&lt;?php wp_footer(); ?&gt;</code> were in the proper places in the code.</p>
<p>Before I get to the code, I want to spend a little time talking about the significance of wp_head() and wp_footer().  These 2 functions are the key to functionality of a lot of plugins and are the real work horses of themes.  The wp_head and wp_footer functions allow WordPress core and plugins to hook into your theme either directly before the <code>&lt;/head&gt;</code> or <code>&lt;/body&gt;</code> html tags in your theme and perform actions.  The majority of the time these actions are used to output style sheets or JavaScript, for use by plugins.  WordPress core uses it to output a lot of good functionality such as relational links to your RSS and ATOM feeds into the head of the document.  <a href="http://josephscott.org/archives/2009/04/wordpress-theme-authors-dont-forget-the-wp_head-function/">Joseph Scott</a> wrote about this nearly a year ago.  His post is fairly short but does a good job at explaining why it is important to include these functions.</p>
<p>Back to the original discussion, which was how do we detect whether or not wp_head and wp_footer are called in the active theme, and if called are they called, was it from the proper locations?</p>
<p>In my proof of concept plugin, we hook into admin_init, which will actually use wp_remote_get() to retrieve the frontend of our WordPress site.  It calls the url with 2 query vars, that if present will cause the plugin to hook into wp_head and wp_footer and output some content that we will later look for.  If the response was successful, as in returning a 200 response code, we will look at the content to see if <code>&lt;!--wp_head--&gt;</code> and <code>&lt;!--wp_footer--&gt;</code> are present.  If they are not we will see an admin notice telling us which problems were found.  If those strings were found but they were not found directly before <code>&lt;/head&gt;</code> or <code>&lt;/body&gt;</code> the notice will alert you of such.</p>
<p>Without further adieu:</p>
<p><script type='text/javascript' src='http://paste.sivel.net/embed/24.js'></script></p>
<p>Just in case you cannot see the code above, use this link: <a href="http://paste.sivel.net/24">http://paste.sivel.net/24</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2010/04/detect-wp_head-and-wp_footer-from-a-plugin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress Maintenance Mode Without a Plugin Part 3</title>
		<link>http://sivel.net/2009/10/wordpress-maintenance-mode-without-a-plugin-part-3/</link>
		<comments>http://sivel.net/2009/10/wordpress-maintenance-mode-without-a-plugin-part-3/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 19:23:37 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=839</guid>
		<description><![CDATA[A few months ago I wrote part 1 and part 2 of WordPress Maintenance Mode Without a Plugin. Part 1 covered the basics of using the .maintenance file, and part 2 covered styling the maintenance page using wp-content/maintenance.php. Part 3 &#8230; <a href="http://sivel.net/2009/10/wordpress-maintenance-mode-without-a-plugin-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A few months ago I wrote <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/">part 1</a> and <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/">part 2</a> of WordPress Maintenance Mode Without a Plugin.  <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/">Part 1</a> covered the basics of using the <code>.maintenance</code> file, and <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/">part 2</a> covered styling the maintenance page using <code>wp-content/maintenance.php</code>.  Part 3 covers the short comings of the other 2 by addressing how to let a user log into the admin and allowing logged in users access to the front end of the site while in maintenance mode.</p>
<p>It only takes a little bit of extra code in a file called <code>.maintenance</code> in the root of your WordPress installation to conditionally return a time that falls within the logic described in <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/">part 1</a>.  Now without forther adieu:</p>
<pre>
<code>&lt;?php
function is_user_logged_in() {
    $loggedin = false;
    foreach ( (array) $_COOKIE as $cookie =&gt; $value ) {
        if ( stristr($cookie, &#039;wordpress_logged_in_&#039;) )
            $loggedin = true;
    }
    return $loggedin;
}
if ( ! stristr($_SERVER[&#039;REQUEST_URI&#039;], &#039;/wp-admin&#039;) &amp;&amp; ! stristr($_SERVER[&#039;REQUEST_URI&#039;], &#039;/wp-login.php&#039;) &amp;&amp; ! is_user_logged_in() )
    $upgrading = time();
?&gt;</code>
</pre>
<p>Just drop the above code in the <code>.maintenance</code> file perhaps take a look at <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/">part 2</a> and away you go.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2009/10/wordpress-maintenance-mode-without-a-plugin-part-3/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>WordPress Maintenance Mode Without a Plugin Part 2</title>
		<link>http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/</link>
		<comments>http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 20:12:15 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=710</guid>
		<description><![CDATA[A few days ago I wrote a post about WordPress Maintenance Mode Without a Plugin. A common question that I got afterwards was whether or not the maintenance page could be styled. The answer, is yes it can be. After &#8230; <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A few days ago I wrote a post about <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/">WordPress Maintenance Mode Without a Plugin</a>.  A common question that I got afterwards was whether or not the maintenance page could be styled.  The answer, is yes it can be.</p>
<p>After wp-settings.php determines whether or not to put the blog into maintenance mode it checks to see if there is a file titled <code>maintenance.php</code> located in <code>WP_CONTENT_DIR</code> which is by default <code>wp-content/</code>.</p>
<p>Simply create a file at <code>wp-content/maintenance.php</code> containing the code you want to display the for the maintenance page.  Below is a sample of code based off of the default maintenance page.</p>
<pre><code>&lt;?php
$protocol = $_SERVER[&quot;SERVER_PROTOCOL&quot;];
if ( &#039;HTTP/1.1&#039; != $protocol &amp;&amp; &#039;HTTP/1.0&#039; != $protocol )
	$protocol = &#039;HTTP/1.0&#039;;
header( &quot;$protocol 503 Service Unavailable&quot;, true, 503 );
header( &#039;Content-Type: text/html; charset=utf-8&#039; );
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
    &lt;title&gt;Maintenance&lt;/title&gt;

&lt;/head&gt;
&lt;body&gt;
    &lt;h1&gt;Briefly unavailable for scheduled maintenance. Check back in a minute.&lt;/h1&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php die(); ?&gt;</code></pre>
<p>Modify as needed, add some css, some images and there you go.</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress Maintenance Mode Without a Plugin</title>
		<link>http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/</link>
		<comments>http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 14:04:36 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CoolStuff]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=690</guid>
		<description><![CDATA[Every so often someone asks a question in the WordPress IRC channel that sparks my interest, and in this case the core maintenance mode functionality was one of those questions. I&#8217;ve known for sometime that WordPress has it&#8217;s own maintenance &#8230; <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Every so often someone asks a question in the <a href="irc://irc.freenode.net/wordpress">WordPress IRC channel</a> that sparks my interest, and in this case the core maintenance mode functionality was one of those questions.  I&#8217;ve known for sometime that WordPress has it&#8217;s own maintenance mode functionality since core upgrades were added, however I had never really looked into the functionality.  Hooking into this functionality is really quite simple and effective.</p>
<p>Start by creating a file in the root of your WordPress install (on level with wp-settings.php) called <code>.maintenance</code>.  Note the preceding dot like a <code>.htaccess</code> file; in Linux this is considered a hidden file.  In this file add the following code:</p>
<pre><code>&lt;?php $upgrading = time(); ?&gt;</code></pre>
<p>This code will basically cause the maintenance page to display until you remove the <code>.maintenance</code> file.  In wp-settings.php there are 2 checks to see if it should display the maintenance page.  First, it makes sure that the <code>.maintenance</code> file exists.  Second, it checks that the current time minus the time specified by the <code>$upgrading</code> variable is less than 10 minutes.  Using the code above will insure that it is always less than 10 minutes since <code>time() - time() == 0</code>.  If you want it to display for a certain period of time you would want to use:</p>
<pre><code>&lt;?php $upgrading = 1234567890; ?&gt;</code></pre>
<p>For your usage you would want to replace <code>1234567890</code> with the unix formatted timestamp of the time minus 10 minutes at which you want the maintenance page to stop displaying.</p>
<p>For example if I wanted the maintenance page to stop displaying at November 14, 2013 at 20:13:00, I would really set the <code>$upgrading</code> variable to November 14, 2013 at 20:03:00.  Notice the 03 instead of 13.  In unix time this would look like <code>1384459380</code>.  And the code needed for the <code>.maintenance</code> file would be:</p>
<pre><code>&lt;?php $upgrading = 1384459380; ?&gt;</code></pre>
<p>Take note that if you use a specific time in the <code>.maintenance</code> file and you do not remove the <code>.maintenance</code> file, your users will see your site and not be affected, however in the admin you will see a notice stating, &#8220;An automated WordPress update has failed to complete &#8211; please attempt the update again now.&#8221;  Deleting the .maintenance file will remove this notice.</p>
<p>I&#8217;m sure that this functionality could be wrapped in a plugin, or even better an option added to the core code in the admin.  However, I am happy with just manually creating the file.</p>
<p>For information on modifying or styling the maintenance page see <a href="http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin-part-2/">WordPress Maintenance Mode Without a Plugin Part 2</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2009/06/wordpress-maintenance-mode-without-a-plugin/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>WordPress Update/Install Clarifications and Requirements</title>
		<link>http://sivel.net/2009/03/wordpress-updateinstall-clarifications-and-requirements/</link>
		<comments>http://sivel.net/2009/03/wordpress-updateinstall-clarifications-and-requirements/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 14:00:57 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=555</guid>
		<description><![CDATA[Recently I have been responding to numerous questions about the update/install functionality in WordPress for core, plugins and soon themes. I wanted to take a few moments to make some clarifications and to inform people of the requirements. To update &#8230; <a href="http://sivel.net/2009/03/wordpress-updateinstall-clarifications-and-requirements/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I have been responding to numerous questions about the update/install functionality in WordPress for core, plugins and soon themes.  I wanted to take a few moments to make some clarifications and to inform people of the requirements.</p>
<p>To update the WordPress core or update/install plugins or themes without having to enter your FTP/SSH information you have 2 options:</p>
<ol>
<li>Define the required constants in wp-config.php</li>
<li>Make the necessary file permission/ownership configurations required to use a direct update/install instead of using FTP or SSH</li>
</ol>
<p>For information on achieving the first option see take a look at the follow links:</p>
<ul>
<li><a href="http://codex.wordpress.org/Editing_wp-config.php#FTP.2FSSH_Constants">wp-config.php FTP/SSH Constants</a></li>
<li><a href="http://www.firesidemedia.net/dev/wordpress-install-upgrade-ssh/">Using SSH to Install/Upgrade WordPress by Jon Dingman</a></li>
</ul>
<p>The second option is a little more confusing for some people.  Most people think that as long as they give full write access to the plugins or wp-content directories that they will not be asked for their FTP/SSH connection information.  Unfortunately, this falls short of the requirements for performing a direct update or install.  There are 4 possible methods for performing the file operations.  The operations are &#8216;direct&#8217;, &#8216;ftp&#8217;, &#8216;ssh2&#8242;, and &#8216;ftpsocket&#8217;.  The direct method allows php to do all of the file operations on its own without requiring any external dependencies.  For the &#8216;direct&#8217; method to work, the web server, and by extension php, needs full write access to the files it is trying to modify.</p>
<p>WordPress determines if it can perform a direct update or install by performing a few file operations and looking at the ownership of those file operations.  Here are the steps that WordPress goes through when making the determination.</p>
<ol>
<li>Returns a suitable temporary directory to create a test file (the following is in the order of precedence)
<ul>
<li>If WP_TEMP_DIR is defined it will return this value</li>
<li>If WP_CONTENT_DIR is writable by the web server user it will return the path to the wp-content directory</li>
<li>If you are running PHP 5.2 or newer it will determine the systems temp directory using sys_get_temp_dir()</li>
<li>As a fall back it will return /tmp/</li>
</ul>
</li>
<li>Creates a unique file via touch() in the temporary directory returned in step 1 and returns the path to this temporary file</li>
<li>If the file system owner of wp-admin/includes/file.php and the file system owner of the temporary file that was created are equal to each other then it will use the direct method and then the temporary file is removed
<ul>
<li>The check that is performed uses the file system owner of wp-admin/includes/file.php and not the run time user of that script</li>
<li>This is, in my opinion, the most reliable way to make sure that the user the web server is running as can make modifications to all of the WordPress files</li>
</ul>
</li>
<li>If the check failed to use the direct method it will check for the possibility of using:
<ul>
<li>SSH2</li>
<li>FTP</li>
<li>Sockets (fsockopen, fwrite, fread)</li>
</ul>
</li>
</ol>
<p>So with the above steps for determining whether or not the &#8216;direct&#8217; method can be used there are several things that can be done to allow WordPress to use the &#8216;direct&#8217; method.</p>
<ol>
<li>If you want to do core upgrades as well as plugin and theme upgrades/installs you can change the ownership of all of the WordPress files to be that of what the web server is running as</li>
<li>If you only want the ability to do plugin and theme upgrades/installs you can modify the ownership of wp-content, all of its contents and wp-admin/includes/file.php to be that of what the web server is running as</li>
<li>If you want to do core upgrades as well as plugin and theme upgrades/installs you can set permissions on all of the WordPress files and all of its contents that give the web server write access to those files and then add a filter to the filesystem method by way of a plugin or addition to functions.php</li>
<li>If you only want the ability to do plugin and theme upgrades/installs you can set permissions on wp-content and all of its contents that give the web server write access to those files and then add a filter to the filesystem method by way of a plugin or addition to functions.php</li>
</ol>
<p>I am sure there are about 100 different combinations of the above methods, so feel free to experiment.</p>
<p>Since #1 and #2 are fairly self explanatory I will skip those and explain #3 and #4.</p>
<ol>
<li>Change the file/directory permissions of either the WordPress root or wp-content and all of their contents so that the web server user has the ability to modify those files and write to those directories</li>
<li>Add the following bit of code to either your themes functions.php or to a plugin
<pre><code>add_filter(&#039;filesystem_method&#039;, create_function(&#039;$a&#039;, &#039;return &quot;direct&quot;;&#039;));</code></pre>
</li>
</ol>
<p>In methods 1 and 2 we simply fulfill the requirements needed by WordPress to return the &#8216;direct&#8217; method on its own.  In methods 3 and 4 we have made sure that the web server can do what it needs to the WordPress files and because of this we can tell WordPress to always use the direct method.</p>
<p>I believe that should about cover it.  If I have made any mistakes or forgot to include something please let me know.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2009/03/wordpress-updateinstall-clarifications-and-requirements/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Separating Pings from Comments in WordPress 2.7</title>
		<link>http://sivel.net/2008/10/wp-27-comment-separation/</link>
		<comments>http://sivel.net/2008/10/wp-27-comment-separation/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 13:04:38 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=288</guid>
		<description><![CDATA[WordPress 2.7 has introduced many new features surrounding comments. Of these is AJAX commenting and threaded comments. To take advantage of the later, you must use a function wp_list_comments instead of the old way of looping through the comments array &#8230; <a href="http://sivel.net/2008/10/wp-27-comment-separation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>WordPress 2.7 has introduced many new features surrounding comments.  Of these is AJAX commenting and threaded comments.  To take advantage of the later, you must use a function wp_list_comments instead of the old way of looping through the comments array with a foreach.  Weblog Tools Collection has a good how to on the old way that can be found <a href="http://weblogtoolscollection.com/archives/2008/03/08/managing-trackbacks-and-pingbacks-in-your-wordpress-theme/">here</a>.  </p>
<p>I wanted to get this hashed out before 2.7 goes live so that theme designers and anyone else can implement this in time for the release.</p>
<p>I&#8217;ll be referencing the default theme from 2.7 in this how to.  If you are interested in adding the new commenting features to your current pre 2.7 theme see this <a href="http://ottodestruct.com/blog/2008/09/29/wordpress-27-comments-enhancements/">how to</a> by Otto.</p>
<p>wp_list_comments is not documented yet on the WordPress <a href="http://codex.wordpress.org/">codex</a>.  But some feature that are worth mentioning are the ability to specify the comment type to display and a callback so that you can decide how to structure the output.</p>
<p>Let us start by taking a look at the new comments &#8220;loop&#8221;:</p>
<pre>
<code>&lt;?php if ( have_comments() ) : ?&gt;
	&lt;h3 id=&quot;comments&quot;&gt;&lt;?php comments_number(&#039;No Responses&#039;, &#039;One Response&#039;, &#039;% Responses&#039; );?&gt; to &#8220;&lt;?php the_title(); ?&gt;&#8221;&lt;/h3&gt;

	&lt;ol class=&quot;commentlist&quot;&gt;
	&lt;?php wp_list_comments(); ?&gt;
	&lt;/ol&gt;
	&lt;div class=&quot;navigation&quot;&gt;
		&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_comments_link() ?&gt;&lt;/div&gt;
		&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_comments_link() ?&gt;&lt;/div&gt;
	&lt;/div&gt;
&lt;?php else : // this is displayed if there are no comments so far ?&gt;

	&lt;?php if (&#039;open&#039; == $post-&gt;comment_status) : ?&gt;
		&lt;!-- If comments are open, but there are no comments. --&gt;

	&lt;?php else : // comments are closed ?&gt;
		&lt;!-- If comments are closed. --&gt;
		&lt;p class=&quot;nocomments&quot;&gt;Comments are closed.&lt;/p&gt;

	&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;</code>
</pre>
<p>As you can see it is much simpler than the old comments &#8220;loop&#8221;.  The majority of everything that is happening is now done via the function wp_list_comments.</p>
<p>To remove pings (pingbacks and trackbacks) we only need to make a few small changes.  First open up your themes single.php:</p>
<p>Find the following code:</p>
<pre><code>&lt;?php comments_template(); ?&gt;</code></pre>
<p>And change it to:</p>
<pre><code>&lt;?php comments_template(&#039;&#039;, true); ?&gt;</code></pre>
<p>The above change tells comments_template to create a global array $comments_by_type that we will use later on.</p>
<p>First open up comments.php.</p>
<p>Look for the following code:</p>
<pre><code>&lt;?php if ( have_comments() ) : ?&gt;</code></pre>
<p>Directly below this add:</p>
<pre>
<code>&lt;?php if ( ! empty($comments_by_type[&#039;comment&#039;]) ) : ?&gt;</code>
</pre>
<p>Change this:</p>
<pre><code>&lt;?php wp_list_comments(); ?&gt;</code></pre>
<p>To this:</p>
<pre><code>&lt;?php wp_list_comments(&#039;type=comment&#039;); ?&gt;</code></pre>
<p>Directly below the wp_list_comments function we modified is:</p>
<pre><code>&lt;/ol&gt;</code></pre>
<p>Directly below this add:</p>
<pre><code>&lt;?php endif; ?&gt;</code></pre>
<p>The if statement prevents the comments heading and ol tags from displaying if you only have trackbacks and pingbacks on this post.</p>
<p>Much easier so far, right?</p>
<p>To display the pings we need to insert the following code beneath the endif we just added:</p>
<pre>
<code>&lt;?php if ( ! empty($comments_by_type[&#039;pings&#039;]) ) : ?&gt;
&lt;h3 id=&quot;pings&quot;&gt;Trackbacks/Pingbacks&lt;/h3&gt;

&lt;ol class=&quot;commentlist&quot;&gt;
&lt;?php wp_list_comments(&#039;type=pings&#039;); ?&gt;
&lt;/ol&gt;
&lt;?php endif; ?&gt;</code>
</pre>
<p>The comments &#8220;loop&#8221; should now look like this:</p>
<pre>
<code>&lt;?php if ( have_comments() ) : ?&gt;
	&lt;?php if ( ! empty($comments_by_type[&#039;comment&#039;]) ) : ?&gt;
	&lt;h3 id=&quot;comments&quot;&gt;&lt;?php comments_number(&#039;No Responses&#039;, &#039;One Response&#039;, &#039;% Responses&#039; );?&gt; to &#8220;&lt;?php the_title(); ?&gt;&#8221;&lt;/h3&gt;

	&lt;ol class=&quot;commentlist&quot;&gt;
	&lt;?php wp_list_comments(&#039;type=comment&#039;); ?&gt;
	&lt;/ol&gt;
	&lt;?php endif; ?&gt;

	&lt;?php if ( ! empty($comments_by_type[&#039;pings&#039;]) ) : ?&gt;
	&lt;h3 id=&quot;pings&quot;&gt;Trackbacks/Pingbacks&lt;/h3&gt;

	&lt;ol class=&quot;commentlist&quot;&gt;
	&lt;?php wp_list_comments(&#039;type=pings&#039;); ?&gt;
	&lt;/ol&gt;
	&lt;?php endif; ?&gt;

	&lt;div class=&quot;navigation&quot;&gt;
		&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_comments_link() ?&gt;&lt;/div&gt;
		&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_comments_link() ?&gt;&lt;/div&gt;
	&lt;/div&gt;
 &lt;?php else : // this is displayed if there are no comments so far ?&gt;

	&lt;?php if (&#039;open&#039; == $post-&gt;comment_status) : ?&gt;
		&lt;!-- If comments are open, but there are no comments. --&gt;

	&lt;?php else : // comments are closed ?&gt;
		&lt;!-- If comments are closed. --&gt;
		&lt;p class=&quot;nocomments&quot;&gt;Comments are closed.&lt;/p&gt;

	&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;</code>
</pre>
<p>Now the pings are displayed below the comments.  The above code will show the pings in full comment boxes.  I personally like a simple ordered list with a link and title of the ping.  To achieve this without a foreach (Thanks <a href="http://comox.textdrive.com/pipermail/wp-hackers/2008-October/021973.html">Ryan Boren</a> for the tip!)</p>
<p>Open your themes functions.php file and create a callback function for wp_list_comments.  The following code should be inserted:</p>
<pre>
<code>&lt;?php
function list_pings($comment, $args, $depth) {
       $GLOBALS[&#039;comment&#039;] = $comment;
?&gt;
        &lt;li id=&quot;comment-&lt;?php comment_ID(); ?&gt;&quot;&gt;&lt;?php comment_author_link(); ?&gt;
&lt;?php } ?&gt;</code>
</pre>
<p>Replace this:</p>
<pre>
<code>&lt;ol class=&quot;commentlist&quot;&gt;
&lt;?php wp_list_comments(&#039;type=pings&#039;); ?&gt;</code>
</pre>
<p>With this:</p>
<pre>
<code>&lt;ol class=&quot;pinglist&quot;&gt;
&lt;?php wp_list_comments(&#039;type=pings&amp;callback=list_pings&#039;); ?&gt;</code>
</pre>
<p>If your theme doesn&#8217;t have a functions.php just create it and include the above code.</p>
<p>In this case our full comment &#8220;loop&#8221; should now look like:</p>
<pre>
<code>&lt;?php if ( have_comments() ) : ?&gt;
	&lt;?php if ( ! empty($comments_by_type[&#039;comment&#039;]) ) : ?&gt;
	&lt;h3 id=&quot;comments&quot;&gt;&lt;?php comments_number(&#039;No Responses&#039;, &#039;One Response&#039;, &#039;% Responses&#039; );?&gt; to &#8220;&lt;?php the_title(); ?&gt;&#8221;&lt;/h3&gt;

	&lt;ol class=&quot;commentlist&quot;&gt;
	&lt;?php wp_list_comments(&#039;type=comment&#039;); ?&gt;
	&lt;/ol&gt;
	&lt;?php endif; ?&gt;

	&lt;?php if ( ! empty($comments_by_type[&#039;pings&#039;]) ) : ?&gt;
	&lt;h3 id=&quot;pings&quot;&gt;Trackbacks/Pingbacks&lt;/h3&gt;

	&lt;ol class=&quot;pinglist&quot;&gt;
	&lt;?php wp_list_comments(&#039;type=pings&amp;callback=list_pings&#039;); ?&gt;
	&lt;/ol&gt;
	&lt;?php endif; ?&gt;

	&lt;div class=&quot;navigation&quot;&gt;
		&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_comments_link() ?&gt;&lt;/div&gt;
		&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_comments_link() ?&gt;&lt;/div&gt;
	&lt;/div&gt;
 &lt;?php else : // this is displayed if there are no comments so far ?&gt;

	&lt;?php if (&#039;open&#039; == $post-&gt;comment_status) : ?&gt;
		&lt;!-- If comments are open, but there are no comments. --&gt;

	&lt;?php else : // comments are closed ?&gt;
		&lt;!-- If comments are closed. --&gt;
		&lt;p class=&quot;nocomments&quot;&gt;Comments are closed.&lt;/p&gt;

	&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;</code>
</pre>
<p>One last (optional) task is to modify the comment counts to only reflect the number of comments minus pings.</p>
<p>Open your themes functions.php and add the following code:</p>
<pre>
<code>&lt;?php
add_filter(&#039;get_comments_number&#039;, &#039;comment_count&#039;, 0);
function comment_count( $count ) {
	if ( ! is_admin() ) {
		global $id;
		$comments_by_type = &amp;separate_comments(get_comments(&#039;status=approve&amp;post_id=&#039; . $id));
		return count($comments_by_type[&#039;comment&#039;]);
	} else {
		return $count;
	}
}
?&gt;</code>
</pre>
<p>Again if your theme doesn&#8217;t have a functions.php just create it and include the above code.</p>
<p>There you have it.  If you have any questions let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2008/10/wp-27-comment-separation/feed/</wfw:commentRss>
		<slash:comments>141</slash:comments>
		</item>
		<item>
		<title>XCache Admin Cannot Login When Using Apache and mod_fcgid</title>
		<link>http://sivel.net/2008/08/xcache-admin-mod_fcgid/</link>
		<comments>http://sivel.net/2008/08/xcache-admin-mod_fcgid/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 19:22:53 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://sivel.net/?p=143</guid>
		<description><![CDATA[I have been helping a friend setup a dedicated server to host his clients sites on and wanted to make things as streamlined and as easy as possible. To do so I installed Apache 2.2, PHP5, XCache and mod_fcgid. I &#8230; <a href="http://sivel.net/2008/08/xcache-admin-mod_fcgid/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been helping a friend setup a dedicated server to host his clients sites on and wanted to make things as streamlined and as easy as possible.  To do so I installed Apache 2.2, PHP5, XCache and mod_fcgid.  I am using suexec with Apache to run the scripts as the users who own the scripts.</p>
<p>I wanted to verify that XCache was working, so I copied the XCache admin directory into one of the document roots and tried to login.  To my surprise I was not able to login even though I was using a known good md5 password hash in the XCache configuration.</p>
<p>It took me about a month of searching to find out that the server variables PHP_AUTH_USER and PHP_AUTH_PW don&#8217;t seem to work with mod_fcgid.  <a href="http://forum.lighttpd.net/topic/4817">This</a> Lighttpd forum entry led me to the XCache admin config.php.</p>
<p>Here is what is required:</p>
<ol>
<li>Create a file in your XCache admin directory called config.php</li>
<li>In this file add the following, using the information you provided in the XCache configuration:
<pre>
<code>&lt;?php
$_SERVER[&#039;PHP_AUTH_USER&#039;] = &#039;admin_username&#039;;
$_SERVER[&#039;PHP_AUTH_PW&#039;] = &#039;admin_password&#039;;
?&gt;</code>
</pre>
</li>
<li>Configure some other means of authentication such as htpasswd or htdigest</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://sivel.net/2008/08/xcache-admin-mod_fcgid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
