<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>phoenixheart - portfolio &amp; more</title>
	
	<link>http://www.phoenixheart.net</link>
	<description>phoenixheart - portfolio &amp; more</description>
	<lastBuildDate>Mon, 18 Jun 2012 01:50:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4</generator>
	<script type="text/javascript">
if (typeof Meebo == "undefined") {
Meebo=function(){(Meebo._=Meebo._||[]).push(arguments)};
(function(q){

	var args = arguments;
	if (!document.body) { return setTimeout(function(){ args.callee.apply(this, args) }, 100); }
	var d=document, b=d.body, m=b.insertBefore(d.createElement('div'), b.firstChild); s=d.createElement('script');
	m.id='meebo'; m.style.display='none'; m.innerHTML='<iframe id="meebo-iframe" />';
	s.src='http'+(q.https?'s':'')+'://'+(q.stage?'stage-':'')+'cim.meebo.com/cim/cim.php?network='+q.network;
	b.insertBefore(s, b.firstChild);

})({network:'phoenixheartnet_bo16we'});	}</script>	<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/phoenixheart" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="phoenixheart" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Configure nginx to serve downloads for Redmine</title>
		<link>http://www.phoenixheart.net/2012/06/configure-nginx-to-serve-downloads-for-redmine/</link>
		<comments>http://www.phoenixheart.net/2012/06/configure-nginx-to-serve-downloads-for-redmine/#comments</comments>
		<pubDate>Sun, 17 Jun 2012 19:32:33 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[redmine]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=474</guid>
		<description><![CDATA[You know, I&#8217;m a big fan of nginx. Lately I&#8217;ve been using redmine as a project management tool too, and it&#8217;s really, really great &#8211; I can&#8217;t recommend it highly enough! Of course redmine is written in Ruby on Rails, or Rails to be short, but setting up is pretty much non-sweat. Once it&#8217;s up [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap dropcap">Y</span>ou know, I&#8217;m a big fan of <a href="/tag/nginx/">nginx</a>. Lately I&#8217;ve been using <a href="http://www.redmine.org/">redmine</a> as a project management tool too, and it&#8217;s really, really great &#8211; I can&#8217;t recommend it highly enough! Of course redmine is written in Ruby on Rails, or Rails to be short, but <a href="http://www.redmine.org/projects/redmine/wiki/RedmineInstall">setting up</a> is pretty much non-sweat. Once it&#8217;s up and running, you&#8217;ll wonder how you could live without it in the past.</p>
<p><a href="http://www.phoenixheart.net/wp-content/uploads/2012/06/nginx-redmine.jpg"><img class="alignnone size-full wp-image-484" title="nginx-redmine" src="http://www.phoenixheart.net/wp-content/uploads/2012/06/nginx-redmine-e1339984213255.jpg" alt="" width="480" height="184" /></a></p>
<p>Since the webserver running redmine, or Rails to be precise &#8211; whatever it is: <a href="http://en.wikipedia.org/wiki/WEBrick">WEBrick</a>, <a href="http://rubygems.org/gems/mongrel">mongrel</a>, <a href="http://code.macournoyer.com/thin/">thin</a>, <a href="http://www.modrails.com/">passenger</a>&#8230; &#8211; is not designed for static file handling, you&#8217;ll most likely end up using nginx as a proxy for the upstream Rails webserver, which often listens at port 3000. Assuming you have the directory structure similar to mine, a typical nginx configuration may look like this:</p>
<pre>server {
    listen       80;
    server_name  cool.redmine.com;

    error_log /var/www/redmine-2.0.1/log/error.log;
    access_log /var/www/redmine-2.0.1/log/access.log;

    location /(themes|javascripts|stylesheets)$ {
        root /var/www/redmine-2.0.1/public;
    }

    # proxy all other requests to thin webserver
    location / {
        proxy_pass        http://127.0.0.1:3000;
    }
}</pre>
<p>This is kindly straightforward: nginx is configured to listen on port 80. Any public requests to the static contents (themes, javascripts, sylesheets) will be served by nginx, directly. All other requests are sent upstream to Rails webserver (<strong>thin</strong> in this case) listening locally on port 3000. We&#8217;re good to go at this point.</p>
<p>&#8220;How about the downloads? Shouldn&#8217;t we let nginx handle the downloads also? Nginx rocks at it!&#8221; you ask. Good question indeed, but not that simple. If we configure nginx that way, all the downloads will be open to public through nginx, which is absolutely not what we want. We want the requests to be authorized by redmine (Rails) first! So with this configuration, Rails will handle the file download requests, authorize them, and send the files on valid authorization, or an error message otherwise.</p>
<p>&#8220;OK so let it be. You said we&#8217;re good to go? Great, let&#8217;s just go then&#8221; you say.</p>
<p>Yes. But no, wait.</p>
<p>Indeed, with the configuration above, we&#8217;re good to go. But not *that* good. There&#8217;s a big problem lying there. And it&#8217;s about how Rails handles file downloads. To serve a file download, Rails firstly loads the whole file into memory (read: RAM) and only starts to send chunk by chunk to the client once this loading process is done. It sucks, if you ask. Even worse: the consumed memory will NOT be released, though it may be reused. Now, it sucks by a megaton! If you have a one-gigabyte file, say a Photoshop PSD, your whole server may be dead.</p>
<p>So now to sum up: First, we want all downloads to be authorized by Rails. Second, we want the file transfers to be done by nginx. Seems legit.</p>
<p>The question is, how?</p>
<p>As a both a nginx and Rails newbie, I dug up the whole internet for an answer. Finally, it came, in a form of &#8211; wait for it &#8211; <strong><a href="http://wiki.nginx.org/XSendfile">X-Accel</a></strong> nginx headers. This will be the scenario:</p>
<ol>
<li>Client (Chrome, Firefox, IE, you name it) sends a request to a download</li>
<li>nginx receives the request</li>
<li>It will then add some indication, literally &#8220;This guy asks for a download. Please authorize him. If OK, let me know the where the file is, so that I can serve him.&#8221;</li>
<li>It will the pass the request upstream to Rails (thin) as normal</li>
<li>Rails authorizes the request successfully</li>
<li>It will then send an internal request to nginx with the file&#8217;s real location</li>
<li>nginx happly serves the file to the lucky user</li>
</ol>
<p>As simple as it sounds, the very few available tutorials really confused me &#8211; they&#8217;re written by advanced users, when again I&#8217;m a newbie. After hours of trying though, I finally made it. Here is the configuration which works for me:</p>
<p>In <code>/var/www/redmine-2.0.1/config/environments/production.rb</code>, before the ending <code>end</code> I added this line</p>
<pre>config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'</pre>
<p>which instructs Rails to detect nginx&#8217;s <code>X-Accel-Redirect</code> header and use it instead of native Rails&#8217; <code>send_file</code>. And the above nginx configuration was replaced with this:</p>
<pre>server {
    listen       80;
    server_name  cool.redmine.com;

    # same old same old
    error_log /var/www/redmine-2.0.1/log/error.log;
    access_log /var/www/redmine-2.0.1/log/access.log;

    location /(themes|javascripts|stylesheets)$ {
        root /var/www/redmine-2.0.1/public;
    }

    # ! The following two blocks enable nginx to serve downloads instead of Rails !
    location /attachments
    {
        proxy_redirect    off;
        proxy_set_header  X-Sendfile-Type   X-Accel-Redirect;
        proxy_set_header  X-Accel-Mapping   /var/www/redmine-2.0.1/files=/files;
        proxy_pass        http://127.0.0.1:3000;
    }

    location /files {
        root /var/www/redmine-2.0.1/;
        internal;
    }

    # proxy all other requests to thin webserver
    location / {
        proxy_pass        http://127.0.0.1:3000;
    }
}</pre>
<p>Two location directives were added: <code>location /attachment</code> and <code>location /files</code>. The first is for public requests (step 1 and 2 in the scenario). The latter is for internal requests (step 6 in the scenario). We don&#8217;t want these internal requests to be reachable by the public, hence the <code>internal</code> keyword. Notice these two lines:</p>
<pre>proxy_set_header  X-Sendfile-Type   X-Accel-Redirect;
proxy_set_header  X-Accel-Mapping   /var/www/redmine-2.0.1/files=/files;</pre>
<p>The first tells Rails that nginx will be serving the file. The second is a map, which can be literally translated into &#8220;If this file is located at <code>/var/www/redmine-2.0.1/files</code>, send me an internal request at <code>/files</code> directive.&#8221; In our case, the file is indeed at that location, so Rails will request nginx at</p>
<pre>location /files {
    root /var/www/redmine-2.0.1/;
    internal;
}</pre>
<p>Here, nginx serves the file, beautifully. And that&#8217;s how I did it! Let me know if this works for you as well.</p>
<img style='display:none' id="post-474-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2012/06/configure-nginx-to-serve-downloads-for-redmine/',title:'Configure nginx to serve downloads for Redmine',tweet:'You know, I&#8217;m a big fan of nginx. Lately I&#8217;ve been using redmine as a project management',description:'You know, I&#8217;m a big fan of nginx. Lately I&#8217;ve been using redmine as a project management'})"><script type='text/javascript'>document.getElementById("post-474-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/6Vwd6uKVglo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2012/06/configure-nginx-to-serve-downloads-for-redmine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new plugin, and hi… it’s been 2 years</title>
		<link>http://www.phoenixheart.net/2012/04/a-new-plugin-and-hi-its-been-2-years/</link>
		<comments>http://www.phoenixheart.net/2012/04/a-new-plugin-and-hi-its-been-2-years/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 05:06:10 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Blahblahblah]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=468</guid>
		<description><![CDATA[So yes, it&#8217;s been 2 years since my last post. Been receiving quite a few comments on this blog still, but I was too busy with other projects (sorry folks). As a result, all of my plugins are now out of date. Some of them may not even work flawlessly with the newer versions of [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">S</span>o yes, it&#8217;s been 2 years since <a href="http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/" title="How to configure nginx to run Kohana on Ubuntu">my last post</a>. Been receiving quite a few comments on this blog still, but I was too busy with other projects (sorry folks). As a result, all of <a href="http://www.phoenixheart.net/wp-plugins/">my plugins</a> are now out of date. Some of them may not even work flawlessly with the newer versions of WordPress as they should anymore. </p>
<p>But now that I have just quit my 9 to 5 life, I think I&#8217;ll dedicate some time into this blog and plugins again. So the first thing I&#8217;m doing is write a new plugin, Lazy Moderator. In short, it populates WordPress comment notification emails with true one-click-to-moderate links &#8211; you don&#8217;t have to log in and confirm. You can read more about it <a href="http://www.phoenixheart.net/wp-plugins/lazy-moderator/">here</a> or <a href="http://wordpress.org/extend/plugins/lazy-moderator/">here</a>.</p>
<p>The next things in plan is a complete overhaul of the old plugins. Though I have the motivation, this is not a promise, so don&#8217;t bet on it.</p>
<p>Wish me luck!</p>
<img style='display:none' id="post-468-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2012/04/a-new-plugin-and-hi-its-been-2-years/',title:'A new plugin, and hi&#8230; it&#8217;s been 2 years',tweet:'So yes, it&#8217;s been 2 years since my last post. Been receiving quite a few comments on this blog',description:'So yes, it&#8217;s been 2 years since my last post. Been receiving quite a few comments on this blog'})"><script type='text/javascript'>document.getElementById("post-468-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/RPkZUflo7vc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2012/04/a-new-plugin-and-hi-its-been-2-years/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to configure nginx to run Kohana on Ubuntu</title>
		<link>http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/</link>
		<comments>http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 07:20:23 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[configure]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[virtual host]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=440</guid>
		<description><![CDATA[As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve started to move away from Apache in favor of nginx (pronounced &#8220;engine-X&#8221;). It&#8217;s not that I really need its power, it&#8217;s just that I wanted to learn something new to break my box. It&#8217;s fairly simple to set up [...]]]></description>
			<content:encoded><![CDATA[<p>As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve started to move away from Apache in favor of <a title="nginx's homepage" href="http://nginx.org/">nginx</a> (pronounced &#8220;engine-X&#8221;). It&#8217;s not that I really need <a title="nginx compared to Apache" href="http://www.joeandmotorboat.com/2008/02/28/apache-vs-nginx-web-server-performance-deathmatch/">its power</a>, it&#8217;s just that I wanted to learn something new to break my box.</p>
<p>It&#8217;s fairly simple to set up and get nginx running with FastCGI and MySQL on Ubuntu &#8211; a very well-written tutorial can be read <a href="http://www.howtoforge.com/installing-nginx-with-php5-and-mysql-support-on-ubuntu-8.10">on HowtoForge</a>, which should take you less than 15 minutes for everything. In this article therefore I will only write about how to configure nginx to actually run a <a href="http://www.kohanaphp.com/">Kohana</a>-powered site, with virtual host and rewriting and such. If you&#8217;re not familiar with Kohana, take a look at <a href="http://www.phoenixheart.net/2009/01/kohana-php-framework/">my article here</a>.</p>
<h3>The prerequisites</h3>
<ul>
<li>I have my Kohana-power site located under <code>/home/phoenixheart/www/my-kohana/</code> directory with proper permission set (owner being www-data, that is).</li>
<li>nginx has been set up properly and listening on port 80, with the configuration directory being <code>/etc/nginx/</code></li>
<li>I want my site to be locally accessible via my-kohana.dev. Any requests to www.my-kohana.dev should be permanently redirected to my-kohana.dev &#8211; which is also called &#8220;force non-www&#8221;.</li>
<li>I want to have neat URL rewriting without &#8220;index.php&#8221;, for example <code>index.php?controller=product&amp;function=get&amp;id=1</code> should be rewritten into <code>/product/get/1</code></li>
<li>I also want that all existing files and directories under the root directory are accessible, except Kohana&#8217;s system directories <code>system</code>, <code>application</code>, and <code>modules</code>. Any attempt to access system files and directories(beginning with dots, like .htaccess or .settings) should be disallowed also.</li>
</ul>
<p>All clear. So let&#8217;s do it!<br />
<span id="more-440"></span></p>
<h3>Set up the virtual host</h3>
<p>The way nginx handles virtual hosts is totally different from Apache, as we can expect. Instead of using .conf files to declare and configure the hosts, nginx, when started, additionally scans through the configuration folder (<code>/etc/nginx</code> in our case) to find (if any) configuration files under 2 directories: sites-available and sites-enabled. So under /etc/nginx/sites-available, create a file called my-kohana.dev with the following content:</p>
<pre class="1" lang="php"><code>server {
    listen   80;
    server_name my-kohana.dev;

    access_log /home/phoenixheart/www/log/my-kohana/access.log; # remember to create this file
    error_log /home/phoenixheart/www/log/my-kohana/error.log; # and this file

    location / {
	root   /home/phoenixheart/www/my-kohana;
	index  index.php;
    }

    location ~ \.php$ {
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param  SCRIPT_FILENAME  /home/phoenixheart/www/my-kohana$fastcgi_script_name;
	include        fastcgi_params;
    }
}</code></pre>
<p>Of course, this is just the basis configuration for the site to get up and running. To continue, we must create a host entry. Open /etc/hosts and add this line:</p>
<pre class="1" lang="php"><code>127.0.0.1	my-kohana.dev www.my-kohana.dev</code></pre>
<p>If this was Apache, we would be good enough to restart the webserver to see the result. But like I said, nginx is different. For nginx to properly recognize and serve our site, we must <em>enable</em> the site by creating a symlink of the configuration file under <code>sites-enabled</code>. We do that as follow:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>ln <span style="color: #339933;">-</span>s <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>sites<span style="color: #339933;">-</span>available<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>sites<span style="color: #339933;">-</span>enabled<span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>kohana<span style="color: #339933;">.</span>dev<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Now, let&#8217;s restart nginx. Open Terminal and type:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>sudo <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>init<span style="color: #339933;">.</span>d<span style="color: #339933;">/</span>nginx restart<span style="color: #339933;">&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The result should be as followed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>code<span style="color: #339933;">&gt;</span>Restarting nginx<span style="color: #339933;">:</span> the configuration <span style="color: #990000;">file</span> <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>nginx<span style="color: #339933;">.</span>conf syntax is ok
configuration <span style="color: #990000;">file</span> <span style="color: #339933;">/</span>etc<span style="color: #339933;">/</span>nginx<span style="color: #339933;">/</span>nginx<span style="color: #339933;">.</span>conf test is successful
nginx<span style="color: #339933;">.&lt;/</span>code<span style="color: #339933;">&gt;</span></pre></div></div>

<p>If you receive any &#8220;failure&#8221; response, chance is some typos in the configuration.</p>
<p>Now, http://my-kohana.dev should be accessible via the browser (Note that, if Kohana complains about the logs folder inaccessible, try properly setting its owner to www-data). Next step is tweaking the configuration a bit to serve our needs.</p>
<h3>Tweak it up</h3>
<h4>Force non-www</h4>
<p>To force non-www, open sites-available/my-kohana.dev and add these lines at the top:</p>
<pre class="1" lang="php"><code>server {
    listen 80;
    server_name www.my-kohana.dev;
    rewrite  ^/(.*)$  http://my-kohana.dev/$1  permanent;
}</code></pre>
<p>This kind of configuration is very similar to that of Apache, so I would assume there&#8217;s no need to explain. After a nginx restart, all request to http://www.my-kohana.dev should be silently redirected to http://my-kohana.dev.</p>
<h4>Neat URL rewriting</h4>
<p>Again, in sites-available/my-kohana.dev, modify the first <code>location</code> block to the following</p>
<pre class="1" lang="php"><code>location / {
    root   /home/phoenixheart/www/my-kohana;
    index  index.php;

    # this is where the rewriting gets done.
    # refer to http://forum.kohanaphp.com/comments.php?DiscussionID=1505 for more info
    rewrite ^(.+)$ /index.php?kohana_uri=$1 last;
}</code></pre>
<p>But wait! We don&#8217;t want EVERY requests to be re-written. For example, a request to my-kohana.dev/css/style.css should be kept as-is. Same goes with javascripts and images. In short, if the request is for an existing file or folder, we keep it as-is; else, we route it to index.php using rewriting. To achieve that, modify the configuration above to this:</p>
<pre class="1" lang="php"><code>location / {
    root   /home/phoenixheart/www/my-kohana;
    index  index.php;

    if (-f $request_filename) {
        # translated into "if the request is an existing file, break (do nothing)"
        break;
    }
    if (-d $request_filename) {
        # translated into "if the request is an existing directory, break (do nothing)"
        break;
    }

    # the request is not an existing file or directory
    # this is where the rewriting gets done.
    # refer to http://forum.kohanaphp.com/comments.php?DiscussionID=1505 for more info
    rewrite ^(.+)$ /index.php?kohana_uri=$1 last;
}</code></pre>
<h4>Set files and folder accessibilities</h4>
<p>Now, we prohibit access to the sensitive stuffs, including kohana system folders, dot files and directories etc. It&#8217;s fairly simple with nginx. All we need to do is adding two more location blocks, specific for this purpose:</p>
<pre class="1" lang="php"><code>location ~ /\. {
    return 404;
    # or, if you prefer
    #return 403;
    # or even
    #deny all;
}
location ~* ^/(modules|application|system) {
    return 404;
    # or, if you prefer
    #return 403;
    # or even
    #deny all;
}</code></pre>
<p>The final configuration file should look like this:</p>
<pre class="1" lang="php"><code>server {
    listen 80;
    server_name www.my-kohana.dev;
    rewrite  ^/(.*)$  http://my-kohana.dev/$1  permanent;
}

server {
    listen   80;
    server_name my-kohana.dev;

    access_log /home/phoenixheart/www/log/my-kohana.dev.access.log;
    error_log /home/phoenixheart/www/log/my-kohana.dev.error.log;

    location ~ /\. {
        return 404;
    }

    location / {
        root   /home/phoenixheart/www/my-kohana;
        index  index.php;

        if (-f $request_filename) {
            # translated into "if the request is an existing file, break (do nothing)"
            break;
        }
        if (-d $request_filename) {
            # translated into "if the request is an existing directory, break (do nothing)"
            break;
        }

        # the request is not an existing file or directory
        # this is where the rewriting gets done.
        # refer to http://forum.kohanaphp.com/comments.php?DiscussionID=1505 for more info
        rewrite ^(.+)$ /index.php?kohana_uri=$1 last;
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/phoenixheart/www/my-kohana$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~* ^/(modules|application|system) {
        return 403;
    }
}</code></pre>
<p>After another nginx restart, our Kohana instance should run without any hassles.</p>
<p>Typos? Mistakes? Errors? Let&#8217;s hear it in your comment.</p>
<img style='display:none' id="post-440-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/',title:'How to configure nginx to run Kohana on Ubuntu',tweet:'As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve st',description:'As a web developer I&#8217;ve been using Apache for a long long time. Recently though, I&#8217;ve st'})"><script type='text/javascript'>document.getElementById("post-440-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/MYSTtIgovIA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2010/03/how-to-configure-nginx-to-run-kohana-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Social Sketches – a free icon set released for Six Revisions</title>
		<link>http://www.phoenixheart.net/2010/01/social-sketches-a-free-icon-set-released-for-six-revisions/</link>
		<comments>http://www.phoenixheart.net/2010/01/social-sketches-a-free-icon-set-released-for-six-revisions/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 02:08:30 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Freebies]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=435</guid>
		<description><![CDATA[Today I&#8217;m so pleased to announce the release of Social Sketches, my hand-drawn icon set exclusively done for Six Revisions. Initially it was made for Referrer Detector on my just-started sketch project The Daily Faces, but then I decided to make it available for public use, hence the featuring on Six Revisions yesterday. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;m so pleased to announce the release of Social Sketches, my hand-drawn icon set exclusively done for Six Revisions. Initially it was made for Referrer Detector on my just-started sketch project <a href="http://dai.lyfaces.com">The Daily Faces</a>, but then I decided to make it available for public use, hence <a href="http://sixrevisions.com/freebies/icons/social-sketches-exclusive-free-hand-sketched-icon-set/">the featuring on Six Revisions</a> yesterday.</p>
<p>Here is the preview of the set:</p>
<p><img class="shot" title="Social Sketches Preview" src="/wp-content/uploads/2010/01/social-sketches-preview.jpg" alt="" width="435" height="512" /></p>
<p>For more information and download, please head to <a href="http://sixrevisions.com/freebies/icons/social-sketches-exclusive-free-hand-sketched-icon-set/">Six Revisions&#8217; post</a>.</p>
<p>P.S. I have a plan to add some more icons into the set, so stay tuned <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img style='display:none' id="post-435-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2010/01/social-sketches-a-free-icon-set-released-for-six-revisions/',title:'Social Sketches &#8211; a free icon set released for Six Revisions',tweet:'Today I&#8217;m so pleased to announce the release of Social Sketches, my hand-drawn icon set exclus',description:'Today I&#8217;m so pleased to announce the release of Social Sketches, my hand-drawn icon set exclus'})"><script type='text/javascript'>document.getElementById("post-435-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/K7tsZ1-eW9k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2010/01/social-sketches-a-free-icon-set-released-for-six-revisions/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>New domain hack idea</title>
		<link>http://www.phoenixheart.net/2009/12/new-domain-hack-idea/</link>
		<comments>http://www.phoenixheart.net/2009/12/new-domain-hack-idea/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 06:29:36 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Blahblahblah]]></category>
		<category><![CDATA[domain hack]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=420</guid>
		<description><![CDATA[Today, I happened to visit The Daily Monster. It&#8217;s a very cool site, I highly recommend you guys to visit it. This post is not about Stefan and his monsters however, but about some domain hack ideas that I&#8217;ve just come up with today. In case you&#8217;re not familiar with the term, Wikipedia has a [...]]]></description>
			<content:encoded><![CDATA[<p><span class="drop-cap">T</span>oday, I happened to visit <a href="http://344design.typepad.com/">The Daily Monster</a>. It&#8217;s a very cool site, I highly recommend you guys to visit it.</p>
<p>This post is not about <a href="http://344design.typepad.com/about.html">Stefan</a> and his monsters however, but about some domain hack ideas that I&#8217;ve just come up with today. In case you&#8217;re not familiar with the term, Wikipedia has a clear definition for <a href="http://en.wikipedia.org/wiki/Domain_hack">domain hack</a>:</p>
<blockquote><p>A domain hack (sometimes known as a domain name hack) is an unconventional domain name that combines domain levels, especially the top-level domain (TLD), to spell out the full &#8220;name&#8221; or title of the domain. Well-known examples include blo.gs, del.icio.us, and cr.yp.to.</p></blockquote>
<p>So upon visiting The Daily Monster, I was quite surprise to see it didn&#8217;t have its own domain name. I was expecting something like thedailymoster.com or dailymonster.com or dailymonsters.com or so, but it turned out that the url was a Typepad subdomain, not a standalone. I totally believe that content is King, but a good domain name in this case would be the crown. I was telling myself &#8220;Maybe the domains had been purchased by other guys&#8221; and I was right &#8211; none of them are available.</p>
<p>Then, I thought based on this &#8220;one design a day&#8221; concept I&#8217;d do a similar site on my own. &#8220;Daily face&#8221;, how is that? A drawing of a face each day. I used to sketch a lot, sometimes with pencil, sometimes with the computer mouse, like this one:</p>
<p><img class="shot" src="/wp-content/uploads/2009/12/face.jpg" alt="One of my sketches" /><span id="more-420"></span></p>
<p>The domain name I came up with was of course &#8220;dailyface.com&#8221;. Needless to say, the domain was not available. So I tried some domain hacks. The result I got in the end was dai.lyface.com. The domain name is lyface.com, and &#8220;dai&#8221; is a subdomain.</p>
<p>Now comes the interesting part. If you don&#8217;t notice, the domain name starts with &#8220;ly&#8221;. Which means, I can add a lot of cool subdomains. To name just a few:</p>
<ul>
<li>week.lyface.com</li>
<li>month.lyface.com</li>
<li>year.lyface.com</li>
<li>ug.lyface.com</li>
<li>sil.lyface.com</li>
<li>friend.lyface.com</li>
<li>f.lyface.com</li>
<li>li.lyface.com</li>
<li>on.lyface.com</li>
<li>bel.lyface.com (LOL&#8217;ed at this)</li>
<li>free.lyface.com</li>
<li>etc. and etc.</li>
</ul>
<p>You can see, with one domain name I can come up with many different sudomains to hold different contents. I can use &#8220;week.lyface.com&#8221; to showcase best drawing each week; same goes with monthly and yearly. You can tell similarly with ug.lyface.com, sil.lyface.com, friend.lyface.com etc. In short, any word ending with &#8220;ly&#8221; can be used to create a meaningful subdomain. Guess what, we have <a href="http://www.libyanspider.com/services/lydomains/words_end_with_ly.php">8742</a> such words!</p>
<p><img class="shot" src="/wp-content/uploads/2009/12/web.jpg" alt="The web has no limit" /><br />
<small>Image credit: <a href="http://www.flickr.com/photos/ecstaticist/1340787730/">ecstatistic</a></small></p>
<p>You get what I mean now? If you manage to get a domain starting with &#8220;ly&#8221;, the sky is your limit. The potential is huge. I don&#8217;t know if they are available or not, but here is a list of such domains I&#8217;ve just come up with: lymovies, lysports, lysports, lygames, lymusic, lysongs, lystuffs, lyeverything, lytips, lyinspirations, lythemes, lydesigns, lyhacks, lytricks, lyphotos, lypics, lystories, lyfun, lylullabies, lychance, lymeet, lynews etc.</p>
<p>Exactly the same concept can be applied to &#8220;ed&#8221;. Here we go: tir.edcoder.com, bor.edcoder.com, inb.edcoder.com, r.edcoder.com, hat.edcoder.com&#8230;</p>
<p>This is especially effective if you want to build up a network of your site, revolving a central concept.</p>
<p>What do you think? Am I reinventing the wheel?</p>
<img style='display:none' id="post-420-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/12/new-domain-hack-idea/',title:'New domain hack idea',tweet:'Today, I happened to visit The Daily Monster. It&#8217;s a very cool site, I highly recommend you gu',description:'Today, I happened to visit The Daily Monster. It&#8217;s a very cool site, I highly recommend you gu'})"><script type='text/javascript'>document.getElementById("post-420-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/Y8n6nKBSY1I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/12/new-domain-hack-idea/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>WordPress: Thank that first time commentator!</title>
		<link>http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/</link>
		<comments>http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 05:12:08 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Blahblahblah]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[user interaction]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress hack]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=392</guid>
		<description><![CDATA[Thumbnail credit: Premshree Pillai To a website, comments are important &#8211; this you must agree. But not all visitors leave comments &#8211; in fact, very, very few. Most of them care about the content only, and tend to leave (bounce) the site right after getting the information they need (so sad a life, huh?) Many [...]]]></description>
			<content:encoded><![CDATA[<p><small>Thumbnail credit: <a href="http://www.flickr.com/photos/premshree/">Premshree Pillai</a></small></p>
<p><span class="drop-cap">T</span>o a website, comments are important &#8211; this you must agree. But not all visitors leave comments &#8211; in fact, very, very few. Most of them care about the content only, and tend to leave (bounce) the site right after getting the information they need (so sad a life, huh?)</p>
<p>Many tips have been introduced and used to encourage visitors to contribute to your site via comments. To my knowledge, and to name a few:</p>
<ul>
<li>Use dofollow links in comments. By default, WordPress and other blogging systems mark links in comments with <code>rel="nofollow"</code> attribute. This attribute tells search engines to not follow the links, which means the commenter&#8217;s site will not be able to share any Google juice with you. While effective in fighting spammers, this technique may a bit disappoint the real visitors. Plugins like <a href="http://wordpress.org/extend/plugins/sem-dofollow/">Dofollow</a> address this problem and remove &#8220;nofollow&#8221; attribute from comment links.</li>
<li>Further promote the commenter&#8217;s blog (if any). <a href="http://wordpress.org/extend/plugins/commentluv/">CommentLuv</a> is a plugin that &#8220;will visit the site of the comment author while they type their comment and retrieve a selection of their last blog posts, tweets or digg submissions which they can choose one from to include at the bottom of their comment when they click submit&#8221;.</li>
<li>Choose a (random) comment to give small prizes such as free ebooks, preminum themes etc.</li>
<li>Explicitly ask the readers to give comments at the end of the article &#8211; &#8220;Please share your thoughts&#8221;, &#8220;What do you think?&#8221;, &#8220;What say you?&#8221; etc. etc.</li>
</ul>
<p>Today I would like to mention another method to encourage commenting. Though this won&#8217;t likely attract more commenters, it may encourage existing ones to leave more comments and become more effective contributors.</p>
<p>The method is called &#8220;Thank first time commenters&#8221; and it works like this: <span id="more-392"></span></p>
<p>Normally when a visitor leaves a comment for the first time on your blog, the comment is displayed under &#8220;awaiting moderation&#8221; status and visible to him only. When there&#8217;s nothing wrong with this approach, it&#8217;s not really interesting for the commenter himself. Now how about showing him a &#8220;thank you&#8221; or &#8220;welcome&#8221; message, or better, a whole page, for the first time contributing his [great] ideas to your site? This time it&#8217;s much cooler!</p>
<p>Let&#8217;s turn the idea into real action for a WordPress site.</p>
<h3>Step 1. Detect first time commenter</h3>
<p><img class="shot" src="/wp-content/uploads/2009/11/comments.gif" alt="Comments" width="470" height="136" /><br />
<small>Original image from <a href="http://www.flickr.com/photos/chrismar/">Chrismar</a></small></p>
<p>To detect whether the comment author is leaving his first comment on you site, we need to <em>hook</em> into one of the comment-related functions (you can read about hooks <a href="http://codex.wordpress.org/Plugin_API">here</a>). For this purpose I use <strike><code>comment_post()</code>, but there may be some other alternatives which I don&#8217;t know about</strike> <code>comment_post_redirect</code> filter. This filter is applied just before WordPress redirects the commentator after him posting a comment &#8211; exactly what we need. </p>
<p>In the theme&#8217;s <code>functions.php</code> page, add these lines:</p>
<pre class="1" lang="php"><code>add_filter('comment_post_redirect', 'check_first_time_comment');

/*
 * This functions accepts one parameter being the location to redirect commentators to
 */
function check_first_time_comment($location)
{
    global $comment; // get the comment from global variables

    // if it's not "unapproved", don't modify the redirect location
    if (0 != $comment-&gt;comment_approved) return $location;

    // now check if it's really the first time the commenter comments
    // to do this, we check the number of comments this author have left on our site
    global $wpdb;
    $sql = "SELECT COUNT(comment_ID) from {$wpdb-&gt;prefix}comments WHERE comment_author_email='{$comment-&gt;comment_author_email}'";

    if ($wpdb-&gt;get_var($sql) &gt; 1) return $location; // he's left more than 1 comment - do nothing with him

    //--- if we reach here, this is the first comment he leaves on our site. Do our stuffs now! ---//

    // first save the comment data into session. We'll use it later
    if (!session_id()) session_start();
    $_SESSION['first_time_comment'] = serialize($comment);

    // now modify the $location so that WordPress redirects this commentator to our special page
    return '/thank-you-for-contribution/';
}</code></pre>
<p>What the code does is pretty self-descriptive. The function <code>check_first_time_comment($location)</code> is triggered just before WordPress redirects the commentator to a location (being the post, the page, or the error page). It takes one parameter, being the location url. Upon triggered, it checks for the status of the comment and only does its deeds if the comment is &#8220;unapproved&#8221; (status code 0). Then, it does a further check to see if this is really the first time the comment author leaves a comment on the site with the email address. If this is true, it saves the comment data into session for later retrieval, and modifies the location string to redirect the commenter to the thank you page.</p>
<h3>Step 2. Create a &#8220;Thank you&#8221; landing page</h3>
<p><img class="shot" src="/wp-content/uploads/2009/11/thanks-narrow.jpg" alt="Thank you!" width="470" height="130" /><br />
<small>Original image by <a href="http://www.flickr.com/photos/premshree/">Premshree Pillai</a></small></p>
<p>This is the page where our valuable commenter is redirected to. To create such a page, first copy page.php in the theme folder into thank-you-page.php. Open it and locate these lines on the top:</p>
<pre class="1" lang="php"><code>&lt;?php
/*
Template Name: Page
*/
?&gt;</code></pre>
<p>Change the template name to something descriptive like &#8220;Thank You Page&#8221;, and add some logic, like this:</p>
<pre class="1" lang="php"><code>&lt;?php
/*
Template Name: Thank You Page
*/
if (!session_id()) session_start();
if (!isset($_SESSION['first_time_comment']))
{
    // the page should not be directly accessed
    header('Location: /');
    exit();
}

// now get the comment data from session and utilize it
$first_time_comment = unserialize($_SESSION['first_time_comment']);
// clear the session
unset(unserialize($_SESSION['first_time_comment']);
$the_post = get_post($first_time_comment-&gt;comment_post_ID); // get the post of the comment
if (empty($the_post))
{
    // for some reason, we cannot find the post.
    // The action here depends on you. For me I redirect to home.
    header('Location: /');
    exit();
}

// tell the browser not to cache this page in anyway
// !IMPORTANT: You may also want to exclude this page from cache plugins too!
header("Cache-Control: no-cache, must-revalidate");

/*
"Thank you" content goes here
With the post on hand, you can enrich this thank you page with:
- similar posts
- posts in the same categories
- random posts
- most read posts
- most commented posts etc.
*/
?&gt;</code></pre>
<p>Save the template. Now go to WordPress control panel, create a new page with &#8220;Thank You Page&#8221; as the template, and <code>thank-you-for-contribution</code> as the slug. You may want to disable ping and comments for the page too. </p>
<p>There! Your blog is now ready to welcome the first time commentators!</p>
<p>But wait&#8230; there&#8217;s still a catch.</p>
<h3>Step 3. Post-production</h3>
<p>Now, if you list down your pages somewhere on your blog, &#8220;Thank You&#8221; page will stupidly appear. The fix is easy: <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">exclude the page ID</a>. Also, if you have a cache plugin installed, it&#8217;s best to exclude Thank You page from caching.</p>
<p>Want to see it in action? Just leave a comment here as a new commentator!</p>
<img style='display:none' id="post-392-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/',title:'WordPress: Thank that first time commentator!',tweet:'Thumbnail credit: Premshree Pillai To a website, comments are important &#8211; this you must agree.',description:'Thumbnail credit: Premshree Pillai To a website, comments are important &#8211; this you must agree.'})"><script type='text/javascript'>document.getElementById("post-392-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/M3p9b93_9Jw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/11/thank-that-first-time-commentator/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>How I sped up my Thica.net</title>
		<link>http://www.phoenixheart.net/2009/10/how-i-sped-up-thica-net/</link>
		<comments>http://www.phoenixheart.net/2009/10/how-i-sped-up-thica-net/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:44:08 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Blahblahblah]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=377</guid>
		<description><![CDATA[Thumbnail credit: Amnemona If you didn&#8217;t notice, I have another site called Thica.net &#8211; Vietnam poetry network, a WordPress (what else) powered blog dedicated to poems in Vietnamese. The site is receiving about 60K of views per month, which is 12x to that of the moment when it was started back on March 2008, and [...]]]></description>
			<content:encoded><![CDATA[<p><small>Thumbnail credit: <a href="http://www.flickr.com/photos/marinacvinhal/">Amnemona</a></small></p>
<p><span class="drop-cap">I</span>f you didn&#8217;t notice, I have another site called <a href="http://www.thica.net">Thica.net &#8211; Vietnam poetry network</a>, a WordPress (what else) powered blog dedicated to poems in Vietnamese. The site is receiving about 60K of views per month, which is 12x to that of the moment when it was started back on March 2008, and I&#8217;m rather happy about it.</p>
<p>About one month ago, Thica.net started to become very slow and tent to produce strange problems. More than often it threw 503 Internal Server Error just when I attempt to add a new post, or 404 Page Not Found for a page that I <em>knew</em> it was there, such as admin panel, plugin section etc. After some deep look inside, I decided that my site was too bloated and then it was time to optimize things to start it up. To admit, the result is nowhere near perfection, but it satisfies my need. So I think I&#8217;ll share with you here.</p>
<h4>1. Eliminate unused plugins</h4>
<p><img class="shot" src="/wp-content/uploads/2009/10/jigsaw.jpg" alt="Plugins" width="470" height="136" /><br />
Original image by <a href="http://www.flickr.com/photos/smackfu/">smackfu</a></p>
<p>Being a developer, I&#8217;m a big fan of plugins and addons. My Firefox has about 30 addons, ranging from <a href="https://addons.mozilla.org/firefox/addon/1865">Adblock Plus</a> to <a href="http://www.ultrareach.com/">UltraSurf</a> (I&#8217;m living in a communist country FYI) and <a href="https://addons.mozilla.org/en-US/firefox/addon/5369">YSlow</a>. Similarly, Thica.net had like 50 plugins, active and inactive alike. So you know, plugins power up WordPress in many ways, but on the downside slow it down because of all the added functions, hooks, data and so on. Some plugins are even terribly written (like one random post plugin which gets <strong>ALL</strong> posts from the database and uses PHP loop to get 5 random posts &#8211; WTH) and may cause serious problems: slowness, security holes, or even crashes your site. <span id="more-377"></span></p>
<p>So I dedicated my time filtering the plugins &#8211; which were <em>really</em> needed, which may be replaced by hacks and/or other inexpensive methods, which may be replaced with another plugin not as bloated, and which were totally useless. For instance, <a href="http://wordpress.org/extend/plugins/akismet/">Askimet</a>, <a href="http://wordpress.org/extend/plugins/ozh-admin-drop-down-menu/">Ozh&#8217; Admin Drop Down Menu</a>, <a href="http://wordpress.org/extend/plugins/google-sitemap-generator/">Google XML Sitemaps</a>, and <a href="http://wordpress.org/extend/plugins/login-lockdown/">Login LockDown</a> were definitely kept. I&#8217;m now using my own functions to get the random and most read posts, searching for a SEO plugin in place of <a href="http://wordpress.org/extend/plugins/all-in-one-seo-pack/">All In One SEO Pack</a> as for some reasons <a href="http://wordpress.org/extend/plugins/platinum-seo-pack/">Platinum SEO Pack</a> didn&#8217;t fit my needs, and have trashed away tens of unused plugins. By &#8220;trashing away&#8221;, I mean deleting from the hard drive, as inactive plugins still waste WP resource &#8211; it still has to look them up and check for their status anyway.</p>
<h4>2. Use a total cache solution</h4>
<p><img class="shot" src="/wp-content/uploads/2009/10/db.jpg" alt="Database" width="470" height="136" /><br />
Original image by <a href="http://www.flickr.com/photos/adesigna/">adesigna</a></p>
<p>To a busy application &#8211; web or non-web alike, caching is vital. For as far as I know WordPress is not as bloated as other CMS (Joomla, Drupal, Magento to name a few), but its performance has rooms to be improved. I had been using <a href="http://wordpress.org/extend/plugins/wp-super-cache/">WP SuperCache</a> for quite a while and the performance was good enough, until the problems occurred and I realized that it had some extra features that I didn&#8217;t need at all. Then I sought out for some alternatives, like <a href="http://wordpress.org/extend/plugins/w3-total-cache/">W3 Total Cache</a>, <a href="http://wordpress.org/extend/plugins/askapache-crazy-cache/">Crazy Cache</a> etc. <a href="http://www.satollo.net/plugins/hyper-cache">HyperCache</a> is where I stopped at &#8211; just a matter of personal opinion, and I&#8217;m happy with it so far.</p>
<p>But HyperCache alone was not enough in my case. Don&#8217;t you know that for a complete page to be served, WordPress has to make like a bunch of continuous calls to the database? My Thica.net for instance, makes an average of 50 MySQL queries for the home page and 80 to 90 queries for each single page. That&#8217;s rather expensive isn&#8217;t it?</p>
<p>Lucky me, there&#8217;s another kind of caching solution called database caching. As most of the query results don&#8217;t change from time to time &#8211; the post content, the categories, the tags&#8230; often remain the same &#8211; they can be cached for later use. For this purpose I installed <a href="http://wordpress.org/extend/plugins/db-cache-reloaded/">DB Cache Reloaded</a> and &#8211; just like magic &#8211; almost all of the queries (85 over 90 for example) are now served from the cache. You must admit, that&#8217;s a huge improvement. My host should thank me for not bombing their server!</p>
<h4>3. Staticalize WordPress variables</h4>
<p><img class="shot" src="/wp-content/uploads/2009/10/phpcode.jpg" alt="Plugins" width="470" height="136" /></p>
<p>WordPress is so flexible &#8211; almost anything can be customized. That&#8217;s definitely great. But sometimes the greatness comes a bit too far from necessity. If you open a normal header.php file from a normal theme, 99% chance is you&#8217;ll see these lines:</p>
<pre lang="html4strict" class="1"><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" &lt;?php language_attributes(); ?&gt;&gt;
&lt;meta http-equiv="Content-Type" content="&lt;?php bloginfo('html_type'); ?&gt;; charset=&lt;?php bloginfo('charset'); ?&gt;" /&gt;
&lt;title&gt;&lt;?php wp_title('&amp;laquo;', true, 'right'); ?&gt; &lt;?php bloginfo('name'); ?&gt;&lt;/title&gt;
&lt;?php bloginfo('stylesheet_url'); ?&gt;
&lt;link rel="pingback" href="&lt;?php bloginfo('pingback_url'); ?&gt;" /&gt;</code></pre>
<p>You guessed it, these scripts get the settings from the database. Now let&#8217;s face it: how often would you change your blog name, or the language, or the style sheet URL, or the HTML charset? For me, it&#8217;s once and for all. vi-VN is my site lang, charset is of course UTF-8, and I don&#8217;t have any intention to change them ever. That&#8217;s why in the theme, I replaced the dynamic scripts with static content whenever applicable:</p>
<pre lang="html4strict" class="1"><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="vi-VN"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;link rel="stylesheet" href="http://static.thica.net/css/notepad-chaos.css?ver=1.2.21" type="text/css" media="screen" /&gt;
&lt;link rel="pingback" href="http://www.thica.net/xmlrpc.php" /&gt;
&lt;!-- and so forth --&gt;</code></pre>
<p>This way I saved quite a few of unnecessary queries and made my site run a bit faster.</p>
<h4>4. Follow Yahoo&#8217;s optimization tips</h4>
<p>Have you taken a look at Yahoo!&#8217;s <a href="http://developer.yahoo.com/performance/rules.html">Best Practices for Speeding Up Your Web Site</a>? It is an awesome resource for those who want to optimize their blogs for performance. Among the rules, these are particularly useful for my case and have been implemented:</p>
<h5>4.1. Add an Expires or a Cache-Control Header</h5>
<p><img class="shot" src="/wp-content/uploads/2009/10/clock.jpg" alt="Clock" width="470" height="136" /><br />
Original image by <a href="http://www.flickr.com/photos/laffy4k/">laffy4k</a></p>
<p>An Expires header lets the browser have an idea of when the requested content is expired and needs to be re-downloaded. By setting a content&#8217;s expires header to a far future, you can tell the browser to use the local cached copy instead of retrieving a fresh version from the server, thus save both bandwidth and loading time. Perfect candidates for this are the images, css, javascript etc.</p>
<p>In the .htaccess file of Thica.net&#8217;s root directory, I added these lines:</p>
<pre lang="html4strict" class="1"><code>&lt;IfModule mod_expires.c&gt;
ExpiresActive on
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType image/jpg "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
&lt;/IfModule&gt;</code></pre>
<p>These lines mean &#8220;These images, javascript, and css includes will not be changed for 10 years more, so dear Firefox/Chrome/Opera/Safari/IE, please use their copies from your cache whenever applicable and don&#8217;t put the heavy load on me, thanks&#8221;. The so understanding browser will be ok with such a polite request, and tada, all the specified contents are loaded from the cache in a blink of an eye.</p>
<h5>4.2 Gzip Components</h5>
<p><img class="shot" src="/wp-content/uploads/2009/10/zip.jpg" alt="Zip" width="470" height="136" /><br />
Original image by <a href="http://www.flickr.com/photos/xploded/">Isobel T</a></p>
<p>Now-a-days, all modern browsers support gzipped components. Imagine it like this: first the browser requests for a page. Instead of returning the page as is, the server compresses it and sends the archive back. The browser receives the archive, decompresses it into normal state, and renders the decompressed content normally. Like WinZIP or WinRAR does, but in a web context. Simple?</p>
<p>To take advantage of this technique, once again I opened the .htaccess file and added these lines:</p>
<pre lang="html4strict" class="1"><code>&lt;ifmodule mod_deflate.c&gt;
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
&lt;/ifmodule&gt;</code></pre>
<p>This configuration forces the server to gzip those MIME contents before returning them to the browser. Made a quick test at the <a href="http://www.gidnetwork.com/tools/gzip-test.php">GIDZipTest</a> fot the homepage and I received this result:</p>
<table style="height: 250px; width: 300px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border-bottom: 1px dotted #dadada;">Web page compressed?</td>
<td style="border-bottom: 1px dotted #dadada; text-align: right; font-weight: bold;"><span style="color: green;">Yes</span></td>
</tr>
<tr>
<td style="border-bottom: 1px dotted #dadada;">Compression type?</td>
<td style="border-bottom: 1px dotted #dadada; text-align: right; font-weight: bold;">gzip</td>
</tr>
<tr>
<td style="border-bottom: 1px dotted #dadada;">Size, Markup (bytes)</td>
<td style="border-bottom: 1px dotted #dadada; text-align: right; font-weight: bold;">31,179</td>
</tr>
<tr>
<td style="border-bottom: 1px dotted #dadada;">Size, Compressed (bytes)</td>
<td style="border-bottom: 1px dotted #dadada; text-align: right; font-weight: bold;">7,476</td>
</tr>
<tr>
<td>Compression %</td>
<td style="text-align: right; font-weight: bold;">76.0</td>
</tr>
</tbody>
</table>
<p>So, 3 lines added into the .htaccess file and I reduced 76% of bandwidth (means loading time cut down to 24%). Marvelous.</p>
<h5>4.3 Split Components Across Domains</h5>
<p><img class="shot" src="/wp-content/uploads/2009/10/server.jpg" alt="Servers" width="470" height="136" /><br />
Original image by <a href="http://www.flickr.com/photos/jamisonjudd/">Jamison_Judd</a></p>
<p>Browsers have a limit on how many parallel requests can be sent &#8211; it&#8217;s 2 for Internet Explorer and 4 for Firefox (configurable, but can&#8217;t exceed 8 if I&#8217;m not wrong). This is a per domain value. It is advised that a site&#8217;s components should be distributed on more than one domain to maximize the parallel downloads. So if your HTML is served from site.com, your images are located on img.site.com, and your css files are put on static.site.com, the number of maximum parallel downloads a browser can perform on your site are tripled, and the loading time may be cut by two third or so.</p>
<p>That&#8217;s why I created two subdomains: img.thica.net for the theme images, and static.thica.net for other static contents like style sheets and javascripts. The performance is significantly improved &#8211; my site often finishes loading before I knew it, period.</p>
<h4>The result so far</h4>
<p>Well, my site ran much faster. Unfortunately, the errors kept occurring from time to time still. From the error logs, it showed that somehow my php5 CGI processes were terminated now and then, hence the 503 and 404 errors. </p>
<p>I contacted my host. They said my site was using too much of resource. I told them that a WP-powered site with 2K to 3K of views per day and 2GB of bandwidth a month could hardly use too much resource. So they were like: bandwidth and resource are not the same. Then they blamed my PHP scripts, saying that All in One SEO Pack sucked. &#8220;Then how come it&#8217;s so widely used around this earth?&#8221; I asked. They kept silence, the errors kept happening. </p>
<p>I was forced to use my final weapon.</p>
<h4>5. Switch to another host</h4>
<p><a href="http://wpwebhost.com/affiliate/idevaffiliate.php?id=728_0_1_17"><img class="shot" src="/wp-content/uploads/2009/10/wpwebhost.jpg" alt="WPWebHost" width="470" height="136" /></a></p>
<p>Yes, the final step I took was switching to another host. I asked for reference from many people, and later got convinced by Jean Baptiste Jung, the famous guy behind <a href="http://www.wprecipes.com">WPRecipes</a>, <a href="http://www.catswhocode.com">CatsWhoCode</a>, and most recently <a href="http://www.codeswhoblog.com">CatsWhoBlog</a>, to go with <a href="http://www.wpwebhost.com">WPWebHost</a> (many thanks, Jean!). It was not a smooth migration to be honest, as I had 4 or 5 sites to be relocated, when my old host doesn&#8217;t use cPanel for site controlling. But what I do really, really appreciate is, no matter what the problem was, no matter small or big, they were always there, supportive and helpful. </p>
<p>Well I don&#8217;t want to sound like a salesman, but WPWebHost really rocks. So if you are planning for a move, I highly recommend them. The banner above is in fact an affiliate link, so I would appreciate a lot if you purchase their hosting package via clicking on it <img src='http://www.phoenixheart.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h4>The <em>final</em> result</h4>
<p>That&#8217;s it &#8211; my journey to optimize my Thica.net to make it speedy, and I&#8217;m really pleased with the result: faster load, light footprints, no stupid errors, minimum bandwidth. You may want to check the result yourself at <a href="http://www.thica.net" title="Thica.net - Mạng thi ca Việt Nam">the site itself</a>. What do you think about it / this article / my pidgin English / my bad writing? I&#8217;m happy to see your comments.</p>
<img style='display:none' id="post-377-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/10/how-i-sped-up-thica-net/',title:'How I sped up my Thica.net',tweet:'Thumbnail credit: Amnemona If you didn&#8217;t notice, I have another site called Thica.net &#8211; ',description:'Thumbnail credit: Amnemona If you didn&#8217;t notice, I have another site called Thica.net &#8211; '})"><script type='text/javascript'>document.getElementById("post-377-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/-s2da1RbYOg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/10/how-i-sped-up-thica-net/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Code Snippet 3 – Create post slugs</title>
		<link>http://www.phoenixheart.net/2009/10/code-snippet-3-create-post-slugs/</link>
		<comments>http://www.phoenixheart.net/2009/10/code-snippet-3-create-post-slugs/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 12:20:40 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=328</guid>
		<description><![CDATA[If you&#8217;re used to WordPress, you must have noticed that usually a blog doesn&#8217;t use the default permalink structure (like http://site.com/?p=43, where 43 is the post ID store in the database). Instead, almost all blog owners tend to use the built-in option form to set the permalinks to something similar to http://site.com/a-great-post and leave the [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re used to WordPress, you must have noticed that usually a blog doesn&#8217;t use the default permalink structure (like <code>http://site.com/?p=43</code>, where 43 is the post ID store in the database). Instead, almost all blog owners tend to use the built-in option form to set the permalinks to something similar to <code>http://site.com/a-great-post</code> and leave the rest to Apache&#8217;s mod_rewrite to handle. In this case, <em>a-great-post</em> is called a <em>post slug</em>, or to be short, a slug. According to WordPress Codex:</p>
<blockquote><p>A slug is a few words that describe a post or a page. Slugs are usually a URL friendly version of the post title (which has been automatically generated by WordPress), but a slug can be anything you like. Slugs are meant to be used with permalinks as they help describe what the content at the URL is.</p></blockquote>
<p>In case you are wondering, slugs play a really, really important part in <abbr title="Search Engine Optimization">SEO</abbr>. This is due to the fact that search engines like Google analyze an URL, and if it is relevant to the page&#8217;s content, the page&#8217;s rank point may be increased. Just like to us human, <em>?p=43</em> doesn&#8217;t tell anything, but <em>how-to-create-post-slugs</em> surely does.</p>
<p>So how is a slug generated?<span id="more-328"></span> Most of the time, the post/page title is involved.</p>
<ol>
<li>First, notice that all slugs are in lowercase format</li>
<li>Second, all non-alphanumeric characters &#8211; those ugly &amp;?#$()&#8230; &#8211; are removed.</li>
<li>Third, spaces get replaced by dashes</li>
</ol>
<p>Let&#8217;s <em>codify</em> them into PHP:</p>
<pre class="1" lang="php"><code>function create_slug($post_title)
{
    // 1. convert into lower case
    $post_title = strtolower($post_title);

    // 2. only accepts alphanumerical characters (a-z, 0-9), spaces, and dashes
    // to do that, we use some RegEx magic
    $post_title = preg_replace('/[^a-z0-9 -]/', '', $post_title); 

    // 3. replace the spaces with dashes
    $post_title = str_replace(' ', '-', $post_title);

    return $post_title;
}</code></pre>
<p>Now test the function &#8211; we&#8217;ll be using some real world examples from Digg:</p>
<pre class="1" lang="php"><code>echo create_slug("High-Speed 'Other' Internet Goes Global ") . '';
echo create_slug('Proposed Anti-Piracy Legislation is Flawed, ISP   Says') . '';
echo create_slug('Cheetah, Gecko and Spiders Inspire Robotic Designs (PICS)') . '';
echo create_slug('In-App Sales &amp; iTablet: The Killer Combo to Save Publishing?');</code></pre>
<p>The above code produces:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">code</span>&gt;</span>high-speed-other-internet-goes-global-
proposed-anti-piracy-legislation-is-flawed-isp---says
cheetah-gecko-and-spiders-inspire-robotic-designs-pics
in-app-sales--itablet-the-killer-combo-to-save-publishing<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">code</span>&gt;</span></pre></div></div>

<p>Not bad huh? There are some problems however. First, if the title has continuous spaces, the slug will contains continuous dashes, which is not quite right. Second, much more important, we didn&#8217;t take into account a concept called <a title="Wikipedia article on stop words" href="http://en.wikipedia.org/wiki/Stopwords">stop words</a> &#8211; long story short, stop words are words that don&#8217;t contain important information and are often filtered out from search queries by search engines. A list of English stop words can be found <a title="List of English stop words" href="http://armandbrahaj.blog.al/2009/04/14/list-of-english-stop-words/">here</a>.</p>
<p>With this information on hand, we improve our code a bit:</p>
<pre class="1" lang="php"><code>function create_slug($post_title)
{
    // 1. convert into lower case
    $post_title = strtolower($post_title);

    // 2. only accepts alphanumerical characters (a-z, 0-9), spaces, and dashes
    // to do that, we use some RegEx magic
    $post_title = preg_replace('/[^a-z0-9 -]/', '', $post_title); 

    // 3. replace the spaces with dashes
    $post_title = str_replace(' ', '-', $post_title);

    // 4. deal with stop words. I added '' (empty string) into the stop words array too.
    $stop_words = array('', 'a', 'about', 'above', 'above', 'across', 'after', 'afterwards', 'again', 'against', 'all', 'almost', 'alone', 'along', 'already', 'also','although','always','am','among', 'amongst', 'amoungst', 'amount',  'an', 'and', 'another', 'any','anyhow','anyone','anything','anyway', 'anywhere', 'are', 'around', 'as',  'at', 'back','be','became', 'because','become','becomes', 'becoming', 'been', 'before', 'beforehand', 'behind', 'being', 'below', 'beside', 'besides', 'between', 'beyond', 'bill', 'both', 'bottom','but', 'by', 'call', 'can', 'cannot', 'cant', 'co', 'con', 'could', 'couldnt', 'cry', 'de', 'describe', 'detail', 'do', 'done', 'down', 'due', 'during', 'each', 'eg', 'eight', 'either', 'eleven','else', 'elsewhere', 'empty', 'enough', 'etc', 'even', 'ever', 'every', 'everyone', 'everything', 'everywhere', 'except', 'few', 'fifteen', 'fify', 'fill', 'find', 'fire', 'first', 'five', 'for', 'former', 'formerly', 'forty', 'found', 'four', 'from', 'front', 'full', 'further', 'get', 'give', 'go', 'had', 'has', 'hasnt', 'have', 'he', 'hence', 'her', 'here', 'hereafter', 'hereby', 'herein', 'hereupon', 'hers', 'herself', 'him', 'himself', 'his', 'how', 'however', 'hundred', 'ie', 'if', 'in', 'inc', 'indeed', 'interest', 'into', 'is', 'it', 'its', 'itself', 'keep', 'last', 'latter', 'latterly', 'least', 'less', 'ltd', 'made', 'many', 'may', 'me', 'meanwhile', 'might', 'mill', 'mine', 'more', 'moreover', 'most', 'mostly', 'move', 'much', 'must', 'my', 'myself', 'name', 'namely', 'neither', 'never', 'nevertheless', 'next', 'nine', 'no', 'nobody', 'none', 'noone', 'nor', 'not', 'nothing', 'now', 'nowhere', 'of', 'off', 'often', 'on', 'once', 'one', 'only', 'onto', 'or', 'other', 'others', 'otherwise', 'our', 'ours', 'ourselves', 'out', 'over', 'own','part', 'per', 'perhaps', 'please', 'put', 'rather', 're', 'same', 'see', 'seem', 'seemed', 'seeming', 'seems', 'serious', 'several', 'she', 'should', 'show', 'side', 'since', 'sincere', 'six', 'sixty', 'so', 'some', 'somehow', 'someone', 'something', 'sometime', 'sometimes', 'somewhere', 'still', 'such', 'system', 'take', 'ten', 'than', 'that', 'the', 'their', 'them', 'themselves', 'then', 'thence', 'there', 'thereafter', 'thereby', 'therefore', 'therein', 'thereupon', 'these', 'they', 'thickv', 'thin', 'third', 'this', 'those', 'though', 'three', 'through', 'throughout', 'thru', 'thus', 'to', 'together', 'too', 'top', 'toward', 'towards', 'twelve', 'twenty', 'two', 'un', 'under', 'until', 'up', 'upon', 'us', 'very', 'via', 'was', 'we', 'well', 'were', 'what', 'whatever', 'when', 'whence', 'whenever', 'where', 'whereafter', 'whereas', 'whereby', 'wherein', 'whereupon', 'wherever', 'whether', 'which', 'while', 'whither', 'who', 'whoever', 'whole', 'whom', 'whose', 'why', 'will', 'with', 'within', 'without', 'would', 'yet', 'you', 'your', 'yours', 'yourself', 'yourselves');
    $slug = array();

    // explode() the post title into single words
    $segments = explode('-', $post_title);
    foreach ($segments as $segment)
    {
        // if the segment is not a stop words, add it into $slug array
        if (!in_array($segment, $stop_words))
        {
            $slug[] = $segment;
        }
    }

    // now convert the $slug array into a string with dashes being the connector
    $slug = implode('-', $slug);

    return $slug;
}</code></pre>
<p>Run the previous example again, we have:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">code</span>&gt;</span>high-speed-internet-goes-global
proposed-anti-piracy-legislation-flawed-isp-says
cheetah-gecko-spiders-inspire-robotic-designs-pics
app-sales-itablet-killer-combo-save-publishing<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">code</span>&gt;</span></pre></div></div>

<p>That&#8217;s better, and this time much more usable, isn&#8217;t it? Now the next step should be the database part &#8211; create a `slug` field as a unique key, and start querying on it instead of the ID. You handle it!</p>
<img style='display:none' id="post-328-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/10/code-snippet-3-create-post-slugs/',title:'Code Snippet 3 &#8211; Create post slugs',tweet:'If you&#8217;re used to WordPress, you must have noticed that usually a blog doesn&#8217;t use the d',description:'If you&#8217;re used to WordPress, you must have noticed that usually a blog doesn&#8217;t use the d'})"><script type='text/javascript'>document.getElementById("post-328-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/-hMIk5TIkgA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/10/code-snippet-3-create-post-slugs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Here we go – CDN Rewrites</title>
		<link>http://www.phoenixheart.net/2009/09/here-we-go-cdn-rewrites/</link>
		<comments>http://www.phoenixheart.net/2009/09/here-we-go-cdn-rewrites/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 10:15:34 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[cdn-rewrites]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=325</guid>
		<description><![CDATA[Right after Free CDN was released, I got a request to enhance the plugin to support commercial Content Delivery Networks &#8211; you know, those big guys like Akamai, Limelight, EdgeCast, Velocix etc. The implementation is not too complicated: specify an origin host, and rewrite it into a destination host. That origin is of course usually [...]]]></description>
			<content:encoded><![CDATA[<p>Right after Free CDN was released, I got a request to enhance the plugin to support commercial Content Delivery Networks &#8211; you know, those big guys like Akamai, Limelight, EdgeCast, Velocix etc. The implementation is not too complicated: specify an origin host, and rewrite it into a destination host. That origin is of course usually http://www.a-busy-site.com, and the destination is something a <a href="http://www.valuecdn.com" class="qc">Content Delivery Network</a> would provide you with: http://static.a-busy-site.com, or http://images.a-busy-site.com, or http://a-static-host.com etc. This way, all static contents will be served from that CDN host. </p>
<p>So, instead of developing the enhancement as a new feature for Free CDN, I decided to create a new plugin called CDN Rewrites. <span id="more-325"></span>The implementation was not really a breeze, but in the end it worked rather smoothly. </p>
<p>I would like to thank <a href="http://www.ezsite.us/">Mike Colburn</a> for the idea and being so kind enough to help me with all the documents and testing. Without him this plugin would never see the light. </p>
<p>Head <a href="/wp-plugins/cdn-rewrites/">here for the plugin&#8217;s official page</a>.</p>
<img style='display:none' id="post-325-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/09/here-we-go-cdn-rewrites/',title:'Here we go &#8211; CDN Rewrites',tweet:'Right after Free CDN was released, I got a request to enhance the plugin to support commercial Conte',description:'Right after Free CDN was released, I got a request to enhance the plugin to support commercial Conte'})"><script type='text/javascript'>document.getElementById("post-325-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/23-XSTsKiHA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/09/here-we-go-cdn-rewrites/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>First version of Free CDN WP plugin released!</title>
		<link>http://www.phoenixheart.net/2009/09/free-cdn-first-version-released/</link>
		<comments>http://www.phoenixheart.net/2009/09/free-cdn-first-version-released/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 17:03:10 +0000</pubDate>
		<dc:creator>An</dc:creator>
				<category><![CDATA[Featured]]></category>
		<category><![CDATA[Freebies]]></category>
		<category><![CDATA[Server stuffs]]></category>
		<category><![CDATA[free CDN]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.phoenixheart.net/?p=314</guid>
		<description><![CDATA[Office life has its advantages and disadvantages. On one hand, it keeps me so exhausted and leaves me so little free time for other hobbies &#8211; I&#8217;m talking about my books, my December Flower guitar self-training, my photographic stuffs etc. On the other hand, it does improve my knowledge and skills with all those working [...]]]></description>
			<content:encoded><![CDATA[<p>Office life has its advantages and disadvantages. On one hand, it keeps me so exhausted and leaves me so little free time for other hobbies &#8211; I&#8217;m talking about my books, my <a href="http://www.youtube.com/watch?v=sLPXAcAsLgo">December Flower</a> guitar self-training, my photographic stuffs etc. On the other hand, it does improve my knowledge and skills with all those working requirements.</p>
<p>I&#8217;m rather lucky to be working as an R&amp;D guy in my current company, thus got a (legal) chance to (legally) spare a lot of time for (sometimes illegal) new and cool stuffs. Among them is <abbr title="Content Delivery Network">CDN</abbr>, a solution to distribute (mostly static) contents across a network and let end-user access their copies from the cloud instead of the central server itself, thus reduces bottle neck problems during peak hours. To enterprise websites like those of Microsoft, Yahoo, Amazon, eBay etc., this is vital, as the number of concurrent visitors and downloads very frequently exceeds millions. Some of them build their own CDN, when the others rather hire third party services to handle the load to save time and money. Most well known among these 3rd services are properly <a href="http://www.akamai.com">Akamai</a> and <a href="http://www.limelightnetworks.com/">Limelight</a>, though there is a vast of them, naturally. For instance, Windows 7 downloads (~2GB each!) were served through Akamai network, when the live internet broadcast of Barrack Obama&#8217;s inaugural speech was done with help from Limelight.<span id="more-314"></span></p>
<p>CDN&#8217;s are great as they save websites from heavy loads thus reduces bandwidth and shorten that number on the webmasters&#8217; monthly bills. So why aren&#8217;t they used so popularly? Well, because in general they are expensive, as you can tell. Depending on each CDN&#8217;s price table and the data size, the cost of using a CDN may range from thousands a month, which is unaffordable for like 98% of our blog owners despite of being just a peanut to Yahoo and Microsoft. So unless he is earning millions from selling Photoshop brushes or Google ads on his personal blog, a blog owner would close his eyes and wait for that Digg wave to calm down instead of (dare) using a CDN and survive the typhoon. So the rich keep getting richer and the poor keep remaining poor, life is bitter huh?</p>
<p>Not really (whoo hoo!). Akamai and Limelight are big, but they are not the only. Aside of those commerical CDN&#8217;s, there are some free ones, like <a href="http://www.coralcdn.org/">Coral</a>, which provide us with free CDN &#8211; means free bandwidth. Coral CDN uses peer-to-peer technology in its CDN architecture, thus eliminates the need of maintaining a system of expensive server clusters while still offering an CDN solution with acceptable speed and stability. Long story shot, we small blog owners can also have CDN (on pair with Microsoft, yay!).</p>
<p>It&#8217;s dead simple to get a content (being any of types, but most commonly static contents like images, video clips, music tracks, css, java scripts) served thought Coral. All you have to do is appending <em style="color:#f00; font-weight:bold">.nyud.net</em> to the host name of that content&#8217;s URL and call it done. Try it <a href="http://www.phoenixheart.net.nyud.net">here</a>, <a href="http://www.thica.net.nyud.net">here</a>, and <a href="http://www.digg.com.nyud.net">here</a> to see it yourself. The first time requested, the content is retrieved from the original server and cached on Coral&#8217;s distributed servers. From the second request on, visitors will get a copy of that content from Coral. If the content weights 100KB in size, you&#8217;ve just saved 100KB bandwidth. If you have 1000 requests, it&#8217;s 100MB of bandwidth saved. Piece of cake. </p>
<p>So I was very excited getting to know about Coral and free P2P CDN&#8217;s. Then I told myself: ok, it&#8217;s time for another WordPress plugin &#8211; a &#8220;Free CDN&#8221; one which will rewrite all static URLs (being images, css, js etc.) to take advantage of Coral. Easier said than done, but nonetheless, I managed to get it done (thank you very much <a href="http://omninoggin.com/">Thaya</a>, for the great help on how to capture the whole WordPress HTML stream). Today is the day <a href="/wp-plugins/free-cdn/">Free CDN WordPress plugin</a> is born, cheers! The concept behind this plugin is simple: it looks for static contents inside a WordPress page and rewrites them into Coral-ready format. For example, <em>http://www.yourblog.com/wp-contents/themes/one-room/images/sprites.png</em> will be rewritten into <em>http://www.yourblog.com<strong>.nyud.net</strong>/wp-contents/themes/one-room/images/sprites.png</em> and gets handled by Coral network. </p>
<p>If your blog is rather small and you don&#8217;t have to worry about bandwidth fee / peak times, then it may be not worth your time to lay an eye on this plugin. But if you have a big enough blog with tens of thousands of views a day, and the bandwidth fee is giving you some good nightmare, and the bottle necks are causing you some headaches, then why not <a href="/wp-plugins/free-cdn/">give Free CDN a try</a>? </p>
<img style='display:none' id="post-314-blankimage" onload="Meebo('discoverSharable', {element: ((this.parentNode.className.match('post')) ? this.parentNode : this.parentNode.parentNode) ,url:'http://www.phoenixheart.net/2009/09/free-cdn-first-version-released/',title:'First version of Free CDN WP plugin released!',tweet:'Office life has its advantages and disadvantages. On one hand, it keeps me so exhausted and leaves m',description:'Office life has its advantages and disadvantages. On one hand, it keeps me so exhausted and leaves m'})"><script type='text/javascript'>document.getElementById("post-314-blankimage").onload();</script><img src="http://feeds.feedburner.com/~r/phoenixheart/~4/_rt92ZN896c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.phoenixheart.net/2009/09/free-cdn-first-version-released/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching using disk: basic
Object Caching 810/895 objects using disk: basic

Served from: www.phoenixheart.net @ 2013-05-04 12:17:41 -->
