<?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>Site With The Lamp &#187; PHP</title>
	<atom:link href="http://www.raditha.com/blog/archives/category/php/feed" rel="self" type="application/rss+xml" />
	<link>http://www.raditha.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 23 Jul 2010 05:26:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ImportError: No module named MySQLdb</title>
		<link>http://www.raditha.com/blog/archives/importerror-no-module-named-mysqldb.html</link>
		<comments>http://www.raditha.com/blog/archives/importerror-no-module-named-mysqldb.html#comments</comments>
		<pubDate>Wed, 28 Apr 2010 11:15:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/importerror-no-module-named-mysqldb.html</guid>
		<description><![CDATA[When you see that title,  you are gonna say; &#8216;you need to install the MySQLdb module&#8217;. Well, let me assure you that it&#8217;s already it&#8217;s already there. Provided by MySQL-python-1.2.3-0.4.c1.fc12.x86_64.rpm . On the other hand if you are here because you ran into the same problem and want a solution, but don&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p>When you see that title,  you are gonna say; &#8216;you need to install the MySQLdb module&#8217;. Well, let me assure you that it&#8217;s already it&#8217;s already there. Provided by MySQL-python-1.2.3-0.4.c1.fc12.x86_64.rpm . On the other hand if you are here because you ran into the same problem and want a solution, but don&#8217;t want to listen to my ramble, just scroll down to the bottom to see how it&#8217;s solved.</p>
<p>All this started when I decided to write a small script to analyze the content of a database using python rather than my usual first choice PHP. But I haven&#8217;t really coded anything at all with Python since I learned it nearly two years ago. So I thought, why not use Python, well the time I spent researching the cause of this problem could have been utilized to write the darned thing in PHP, Perl or Java or heck even C.</p>
<p>The last time, I did anything with Python, I ran the scripts either from the command line or using mod_python. I can&#8217;t remember the editor or IDE I was using at the time but I pretty sure it wasn&#8217;t <a href="http://netbeans.org">Netbeans</a>. The problem pops up only when you try to run the script from inside Netbeans itself. The very same script can be executed from the shell using the python interpreter (see, what did I tell you about mysqldb being installed?)</p>
<p>Searching for I<em>mport Error: No module named MySQLdb netbeans</em> came up with a blank. Digging a bit deeper, I realized that Netbeans using the jython intepreter rather than the default python 2.6 interpreter that&#8217;s available on Fedora. That in turn enabled me to dig up a post on <a href="http://stackoverflow.com/questions/2275072/installing-mysqldb-for-django-jython">Stackoverflow</a> which explained that MySQLdb cannot be used with <a href="http://www.jython.org/">jython</a>. You need to use something called zxJDBC instead. Damned if I am going to bother with that. Instead <strong>I just changed the python platform and solved it easily</strong>.</p>
<p>To change the platform, Right Click on the projects root node (the project name in the &#8216;projects tab&#8217;), when the dialog pops up select the &#8216;python&#8217; item from the tree on the left and then change the platform.</p>
<div class="wp-caption aligncenter" style="width: 410px"><a href="/blog/images/python/nb1.gif"><img title="Change Python Platform" src="/blog/images/python/nb1-t.gif" alt="Changing the Python Platform" width="400" height="270" /></a><p class="wp-caption-text">Changing the Python Platform (click to enlarge)</p></div>
<p>If by some chance, the installed python interpreter does not show up here, click the manage button and on the new dialog, choose the &#8216;auto-detect&#8217; button. If today isn&#8217;t your lucky day, netbeans will refuse to find your default python interpreter. But that&#8217;s ok, just run to the command line do a `which python` and then use the path to the interpreter as reported by which to add a &#8216;New&#8217; platform.</p>
<div class="wp-caption aligncenter" style="width: 410px"><a href="/blog/images/python/nb1.gif"><img title="Change Python Platform" src="/blog/images/python/nb2-t.gif" alt="Adding a new python platform" width="400" /></a><p class="wp-caption-text">Adding a new python platform (click to enlarge)</p></div>
<p>Hopefully you might find my older post <a href="http://www.raditha.com/blog/archives/1759.html">ImportError: No module named dom.minidom</a> also to be usefull</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/importerror-no-module-named-mysqldb.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Twitter over capacity and SimpleDB Errors</title>
		<link>http://www.raditha.com/blog/archives/twitter-over-capacity-and-simpledb-errors.html</link>
		<comments>http://www.raditha.com/blog/archives/twitter-over-capacity-and-simpledb-errors.html#comments</comments>
		<pubDate>Mon, 05 Apr 2010 15:40:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/twitter-over-capacity-and-simpledb-errors.html</guid>
		<description><![CDATA[As I write this, &#8216;Twitter is over capacity&#8217;. The fail whale as it&#8217;s popularly known is flying with the help of  a few tweety birds. In between reloads the broken robot (or is that an  alien) with the &#8216;Something is technically wrong&#8217; message also pops up. By quite a coincidence, simpleDB, Amazon&#8217;s cloud hosted [...]]]></description>
			<content:encoded><![CDATA[<p>As I write this, &#8216;Twitter is over capacity&#8217;. The fail whale as it&#8217;s popularly known is flying with the help of  a few tweety birds. In between reloads the broken robot (or is that an  alien) with the &#8216;Something is technically wrong&#8217; message also pops up. By quite a coincidence, <a href="https://aws.amazon.com/simpledb/">simpleDB</a>, Amazon&#8217;s cloud hosted nosql solution is throwing up intermittent errors.  There was a running task on one of our server that was attempting to movie about 11 million records from a Mysql database into SimpleDB, every 50,000 records or so <a href="http://webmasterinresidence.ca/simpledb/">the underlying API</a> produced the following error:</p>
<p style="padding-left: 30px;">PHP Warning:  SimpleDB::batchPutAttributes(): ServiceUnavailable: Service AmazonSimpleDB is currently unavailable. Please try again later<br />
in /var/www/****/SimpleDB/sdb.php on line 1021<br />
Items FAILED<br />
ErrorCode: ServiceUnavailable</p>
<p>However at about the time that twitter went offline, we noticed almost every other insert producing an error. When that happens we have coded our script to sleep a few seconds and retry the insert. The second attempt was completed successfully almost everytime. I went to tweet about it to find that twitter has gone offline.</p>
<p>AFAIK, twitter has not publicly stated what their database platform is. They might do so at chirp so for the moment I am going to hazard a guess that they are using SimpleDB to store some of their data. All their static content is served out of <a href="https://aws.amazon.com/s3/">Amazon S3</a> so this is not a wild guess (I hope). I am now going to leap to the conclusion that the two errors are related and make a fool of myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/twitter-over-capacity-and-simpledb-errors.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Centos 5.4  , PHP 5.3 and Harvard Referencing.</title>
		<link>http://www.raditha.com/blog/archives/centos-5.4-php-5.3-and-harvard-referencing..html</link>
		<comments>http://www.raditha.com/blog/archives/centos-5.4-php-5.3-and-harvard-referencing..html#comments</comments>
		<pubDate>Mon, 01 Mar 2010 11:45:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rad Inks]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[deadinedue]]></category>
		<category><![CDATA[virtualization]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/centos-5.4-php-5.3-and-harvard-referencing..html</guid>
		<description><![CDATA[A couple of days back, we did an update to Deadlinedue, the Harvard reference generator, the moment the database was updated and the new code was put in place, PHP started segfaulting. It was time to decide whether to roll back or press forward. I chose the latter and it resulted in the site been [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days back, we did an update to <a href="http://deadlinedue.com/">Deadlinedue</a>, the Harvard reference generator, the moment the database was updated and the new code was put in place, PHP started segfaulting. It was time to decide whether to roll back or press forward. I chose the latter and it resulted in the site been offline for <a href="http://deadlinedue.com/blog/more-accurate-citations.html">around an hour</a>.</p>
<p style="padding-left: 30px;">I<span style="color: #993300;">t is not possible to assign complex types to nodes in /var/www/deadline/ISBN.php on line 480, referer: http://deadlinedue.com/index.php?lookf<br />
or=http%3A%2F%2Fraditha.com&amp;find=find<br />
*** glibc detected *** /usr/sbin/httpd: double free or corruption (fasttop): 0&#215;81cdfc78 ***</span></p>
<p>PHP is pretty old now, it&#8217;s not something that you expect to segfault, so initially I thought the culprit would be APC &#8211; Advanced PHP Cache. These PHP accelerators or caches are known to crash every once in a while. That can be easily fixed by removing the accelerator. In this case we could afford to do so since we had upgraded the server very recently and optimized the code which resulted in a speed boost and reduced memory usage. I was barking up the wrong tree,  disabling APC didn&#8217;t do any good. So guess it&#8217;s time to upgrade PHP?</p>
<p>Now you might ask, shouldn&#8217;t we have used the same version of PHP in our development and production servers to ensure that this sort of thing didn&#8217;t happen? Right you are but who expects PHP of all things to crash like this. It&#8217;s really rediculous that deadlinedue is hosted in the cloud. So we could easily have made a snapshot of it and started another server in less than 5 minute. We could have tested with that guinea pig and then gone live, but no, I was too cocky.</p>
<p>This is <a href="http://centos.org/">Centos</a> 5.4 and there are no RPMs available for PHP 5.3.1, So it was time to compile from scratch. Which usually means you need to run ./configure about half a dozen times, fixing each of the missing dependencies it rep<span style="color: #000000;">o</span>rts until it completes without error. Fortunately there is plenty of bandwidth on <a href="http://aws.amazon.com/ec2/">Amazon EC2</a> and the servers are blazing fast. Most deps can be installed in less time than it takes to type out the yum install command.</p>
<p>After all this the problem still wasn&#8217;t solved, a lot of modules we needed like JSON , DOM and heck even Mysqli were not getting added!</p>
<p style="padding-left: 30px;"><span style="color: #993300;">PHP Warning:  PHP Startup: apc: Unable to initialize module\nModule compiled with module API=20050922\nPHP    compiled with module API=20090626\nThese optio<br />
ns need to match\n in Unknown on line 0<br />
PHP Warning:  PHP Startup: dbase: Unable to initialize module\nModule compiled with module API=20050922\nPHP    compiled with module API=20090626\nThese opt<br />
ions need to match\n in Unknown on line 0<br />
PHP Warning:  PHP Startup: dom: Unable to initialize module\nModule compiled with module API=20050922\nPHP    compiled with module API=20090626\nThese optio<br />
ns need to match\n in Unknown on line 0<br />
PHP Warning:  PHP Startup: json: Unable to initialize module\nModule compiled with module API=20050922\nPHP    compiled with module API=20090626\nThese opti<br />
ons need to match\n in Unknown on line 0</span></p>
<p>Given enough time, I can track down their causes and fix these errors, but time was exactly what I was not having on my hands. So tried looking around to find out if there are any RPMs available from third party repositories that would update PHP to version 5.3.1. Fortunately there was.  The repo is called <a href="http://www.webtatic.com/blog/2009/06/php-530-on-centos-5/">Web Tactic</a>. Update using the RPMs took just seconds and good news, no more segmentation faults. The bad news is that APC is no longer available.  I tried  I tried &#8216;yum install php-pecl-apc&#8217;  without success. Then tried &#8216;pecl install apc&#8217; and got the following error:</p>
<p style="padding-left: 30px;"><span style="color: #993300;">/tmp/pear/temp/APC/php_apc.c: In function &#8216;zif_apc_compile_file&#8217;:<br />
/tmp/pear/temp/APC/php_apc.c:881: warning: unused variable &#8216;eg_class_table&#8217;<br />
/tmp/pear/temp/APC/php_apc.c:881: warning: unused variable &#8216;eg_function_table&#8217;<br />
/tmp/pear/temp/APC/php_apc.c: At top level:<br />
/tmp/pear/temp/APC/php_apc.c:959: error: duplicate &#8217;static&#8217;<br />
make: *** [php_apc.lo] Error 1<br />
ERROR: `make&#8217; failed</span></p>
<p>Oh well, can live without APC for the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/centos-5.4-php-5.3-and-harvard-referencing..html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Solving a Twitter OAuth and Incorrect Signatures Mystery</title>
		<link>http://www.raditha.com/blog/archives/solving-a-twitter-oauth-and-incorrect-signatures-mystery.html</link>
		<comments>http://www.raditha.com/blog/archives/solving-a-twitter-oauth-and-incorrect-signatures-mystery.html#comments</comments>
		<pubDate>Wed, 25 Nov 2009 10:28:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/solving-a-twitter-oauth-and-incorrect-signatures-mystery.html</guid>
		<description><![CDATA[If you see a Twitter or Facebook app that asks for your username and password you should run a mile. Admittedly OAuth is not anymore secure than CHAP authentication but there is a crucial difference; most people use the same username/password (or at least the same password ) on multiple websites, email addresses, memory cards [...]]]></description>
			<content:encoded><![CDATA[<p>If you see a <a href="http://twitter.com/">Twitter</a> or Facebook app that asks for your username and password you should run a mile. Admittedly <a href="http://oauth.net/">OAuth</a> is not anymore secure than CHAP authentication but there is a crucial difference; most people use the same username/password (or at least the same password ) on multiple websites, email addresses, memory cards and what have you. By necessity when a web app saves your password for Twitter or Facebook or any other site, it has to be encrypted with a symmetric key, which means the plain text version can be easily obtained.</p>
<p>Users don&#8217;t need any special effort for Oauth but developers do. Writing an application that uses OAuth instead of passwords is supposed to take just a wee bit more effort, (but all seasoned programmers know what exactly that means).</p>
<p>One of the issues we ran into was caused by Twitter returning an &#8216;Incorrect signature&#8217; error for List Delete member api calls. The signature was being generated using the <a href="http://github.com/abraham/twitteroauth">TwitterOauthLib</a>. The signature was correct. It worked fine for all other methods excepts for DELETE calls. If you passed in the same parameters to a different Oauth library, you would get the exact same signature so are we seeing a bug in the twitter API?  You might also suspect that this is because the underlying HTTP client library didn&#8217;t support the DELETE HTTP method. In this case it&#8217;s curl and the DELETE method is supported. Nevertheless I tried using an HTTP POST while sending the _method=DELETE parameter as suggested by the <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-DELETE-list-members">Twitter API documentation</a> with out any luck.</p>
<p>On further investigation I found that all the parameters were being posted for both DELETE and POST requests. <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">RFC 2616</a> doesn&#8217;t specify how you should pass parameters (request body or query string) for DELETE requests. I decided to change the TwitterOauth code to include the parameters as query strings (get the <a href="http://www.raditha.com/blog/images/oauth-patch.txt">patch</a>). Sure enough twitter accepted the request without the incorrect signature error.  The modified code now looks like this:</p>
<div style="margin: 20px; overflow: auto; height: 200px;">
<pre>  function http($url, $method, $postfields = NULL) {

    $ci = curl_init();

    /* Curl settings */

    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this-&gt;connecttimeout);

    curl_setopt($ci, CURLOPT_TIMEOUT, $this-&gt;timeout);

    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);

    curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));

    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this-&gt;ssl_verifypeer);

    switch ($method) {

      case 'POST':

        curl_setopt($ci, CURLOPT_URL, $url);

        curl_setopt($ci, CURLOPT_POST, TRUE);

        if (isset($postfields)) {

          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);

        }

        break;

      case 'DELETE':

        curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');

        if (isset($postfields)) {

            curl_setopt($ci, CURLOPT_URL, "{$url}?{$postfields}");

        }

        else

        {

            curl_setopt($ci, CURLOPT_URL, $url);

        }

        break;

      default:

            curl_setopt($ci, CURLOPT_URL, $url);

            break;

    }

    $response = curl_exec($ci);

    $this-&gt;http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);

    $this-&gt;last_api_call = $url;

    curl_close ($ci);

    //if ($this-&gt;format === 'json' &amp;&amp; $this-&gt;decode_json) {

    //  return json_decode($response);

    //}

    return $response;

  }</pre>
</div>
<p>Also had to do a modification to the oAuthRequest method, which was automatically appending the twitterId to the url it&#8217;s not required (and in fact leads to an incorrect link for list methods). That means if you have been using an unpatched TwitterOauth library and have been passing in the twitterId as a parameter, you will have to change that.</p>
<p>Oh and btw, <a href="http://twitter.com/e4c5">follow me on twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/solving-a-twitter-oauth-and-incorrect-signatures-mystery.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>json_encode/json_decode vs serialize/unserialize and fools vs idiots.</title>
		<link>http://www.raditha.com/blog/archives/json_encodejson_decode-vs-serializeunserialize-and-fools-vs-idiots..html</link>
		<comments>http://www.raditha.com/blog/archives/json_encodejson_decode-vs-serializeunserialize-and-fools-vs-idiots..html#comments</comments>
		<pubDate>Sat, 01 Aug 2009 01:01:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Java Script]]></category>
		<category><![CDATA[religion]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/json_encodejson_decode-vs-serializeunserialize-and-fools-vs-idiots..html</guid>
		<description><![CDATA[If you want to write good , fast, memory efficient code (pick any three) you need to start off with good fast memory efficient algorithms. Using fprintf instead of fwrite or  java.util.ArrayList instead of java.util.Vector or $.ajax instead of $.get doesn&#8217;t really make any difference at all. If you spend your life trying to figure [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to write good , fast, memory efficient code (pick any three) you need to start off with good fast memory efficient algorithms. Using fprintf instead of fwrite or  java.util.ArrayList instead of java.util.Vector or $.ajax instead of $.get doesn&#8217;t really make any difference at all. If you spend your life trying to figure out which is faster or takes up less memory you will never get anything done. Sometimes <a href="http://www.raditha.com/blog/archives/readfile-vs-include-echo-vs-print-dont-bother.html">people who ought to know better even shout from the rooftops</a> that you should waste your time trying to shave off a few milliseconds here and there but fortunately there are more wiser heads to shoot them down.</p>
<p>Since PHP added support for JSON encode and decode a lot has been written about how it&#8217;s more efficient than serialize / unserialize and the have got the numbers to proove it too. In one study it was pointed out that json_encode takes 0.63 milli seconds to convert a certain object to text while the serialize function took just 0.41 milliseconds however that author suggests that all existing code that uses serialize/unserialize should be changed to json_encode/json_decode because decode/unserialize more often than encode/serialize and json_decode takes just 1.42ms vs 2.28 ms for unserialize. Another mutt had reproduced the same sort of results on eight different servers. Sure that&#8217;s about a 50% improvement in speed. And if your script just happens to be executed 1,000,000 times you will save a whopping 860 seconds! you will probably get a 100% increment at your next evaluation too.</p>
<p>Most often you want to convert and object to a string because you want to send it over the wire or save it in a database. If your applications appears to be slow it&#8217;s probably because the database query is slow or it takes a lot of time to retrieve the data from the remote server. If it takes two seconds to retrieve/store  the data what difference does it make to shave of 0.0005 of a second by changing from json to php serialize?</p>
<p>I am not saying you should not make any effort to optimize your code at all. Wordpress and Windows OS are examples that scream out for optimization. What I am saying is that you should write your code with a decent algorithm (but don&#8217;t rupture yourself looking for one), then test your app. If you find it&#8217;s slow and doesn&#8217;t scale well, run it through a profiler to find the bottleneck. You will usually find that about 20% of the code takes up about 80% of the execution time sometims it&#8217;s worse. All you need to do is to look at that part of the code and optimize it or perhaps even change the algorithm.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/json_encodejson_decode-vs-serializeunserialize-and-fools-vs-idiots..html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PHP HTTP Clients and on the fly gzip compression.</title>
		<link>http://www.raditha.com/blog/archives/php-http-clients-and-on-the-fly-gzip-compression..html</link>
		<comments>http://www.raditha.com/blog/archives/php-http-clients-and-on-the-fly-gzip-compression..html#comments</comments>
		<pubDate>Sun, 05 Jul 2009 06:00:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/php-http-clients-and-on-the-fly-gzip-compression..html</guid>
		<description><![CDATA[You can speed up your website, by making your web server perform on the fly gzip compression. Any old web server including the lame IIS can do that. Similarly any old web browser including the badly designed, badly written Internet Explorer can transparently decompress this gzipped content. Unfortunately the same cannot be said about some [...]]]></description>
			<content:encoded><![CDATA[<p>You can speed up your website, by making your web server perform on the fly gzip compression. Any old web server including the lame IIS can do that. Similarly any old web browser including the badly designed, badly written Internet Explorer can transparently decompress this gzipped content. Unfortunately the same cannot be said about some HTTP client libraries. But it isn&#8217;t as bad is it sounds. These client libraries simply avoid sending the &#8216;<em>Accept-Encoding: gzip,deflate&#8217;</em> header and the server will respond by not deflating the content. So the only thing you lose is a bit of speed. Well you might lose a bit of money also if you pay by the gigabyte for your bandwidth.</p>
<p>If you are building a web services client with PHP, you can try to combine the PHP HTTP wrapper the zlib extension to read and deflate gzip compressed data. One <a href="http://www.php.net/manual/en/function.gzopen.php">php.net contributed note</a> on php.net suggests to &#8216;daisy chain&#8217; the zlib:// and http:// wrappers ().</p>
<p style="padding-left: 30px;">&lt;?<br />
echo file_get_contents(&#8220;compress.zlib://http://raditha.com/&#8221;, &#8220;r&#8221;);<br />
?&gt;</p>
<p>Another approach is to rely on gzopen.</p>
<p style="padding-left: 30px;">&lt;?</p>
<p style="padding-left: 60px;">$zp = gzopen(&#8220;http://raditha.com/&#8221;, &#8220;r&#8221;);<br />
gzpassthru($zp);</p>
<p style="padding-left: 30px;">?&gt;</p>
<p>They will both echo out the HTML of the web page at http://raditha.com/ &#8211; but appearances can be deceptive. If you analyze the traffic with <a href="http://www.wireshark.org/">wireshark</a> (or any old packet sniffer), you will find that the &#8216;<em>Accept-Encoding: gzip,deflate</em>&#8216; header is <strong>not</strong> being sent and it&#8217;s counterpart &#8216;<em>Content-Encoding: gzip</em>&#8216; is not included in the response. The above code appears to work because the PHP Zlib extension will open uncompressed files without complaining. In other words, when it encounters uncompressed data, gzopen behaves exactly like fopen and gzread behaves like fread.</p>
<p>So if you want to benefit from the deflate module on your webserver, you will need to use your own client library. How to create a client library is beyond the scope of this post, but I will explain how you can set and get the headers and decode the data. In order to make sure that the server compresses the content you need to do:</p>
<p style="padding-left: 30px;">fwrite($this-&gt;socket, &#8220;Accept-Encoding: gzip,deflate\r\n&#8221;);</p>
<p>Usually images and other binary files will not be gzipped, so you need to make sure that the server sends back the &#8216;Content-Encoding: gzip&#8217; header before you actually try to decompress the message body.</p>
<pre>$this-&gt;headerArray = split("\r\n", $this-&gt;headers);
foreach($this-&gt;headerArray as $head)
{
    $parts = split(": ",$head);
    if(strtolower($parts[0]) == 'content-encoding: gzip')
    {
        $gzip=true;
    }
}</pre>
<p>It&#8217;s not a requirement to convert the headers to lower case before comparision; we are just playing safe because sometime you find weird servers not capitalizing the second word in the header. Once you have identified that the content is gzipped, you might be tempted to just use the gzinflate() method to inflate what you read in from the socket.</p>
<p>gzinflate(stream_get_contents($this-&gt;socket, $length-10));</p>
<p>you will only run into an error</p>
<p style="padding-left: 30px;"><span style="color: #993300;"><br />
</span></p>
<p style="padding-left: 30px;"><span style="color: #993300;">PHP Warning:  gzinflate(): data error in /var/www/clients/twitter/RadHTTPClient.php on line 261<br />
PHP Stack trace:<br />
PHP   1. {main}() /var/www/raditha/http-deflate.php:0<br />
PHP   2. RadHTTPClient-&gt;getMessageBody() /var/www/raditha/http-deflate.php::20<br />
PHP   3. gzinflate() /var/www/raditha/RadHTTPClient.php:261</span></p>
<p>It happens because the gzinflate() function <em>doesn&#8217;t expect to deal with the gzip header.</em> The header contains the gzip magic number as well as other flags such as file modification time etc. This header has to be stripped out before you pass it into the gzinflate function.</p>
<pre>if($useGzip)
{
    $b = fread($this-&gt;socket,2);
    if(ord($b[0]) == 0x1f &amp;&amp; ord($b[1]) == 0x8b)
    {
        $gzHead = fread($this-&gt;socket,8);
        $s = gzinflate(stream_get_contents($this-&gt;socket, $length-10));
    }
}</pre>
<p>if the magic number 0&#215;1f8b is not found you can treat the data as already uncompressed data (of course you will need to add the &#8216;else&#8217; to go with it).</p>
<p>One last thing; if you want to enable one the fly gzip compression with Apache all you need to do is to add the following directives to the httpd.conf file</p>
<p style="padding-left: 30px;">LoadModule deflate_module modules/mod_deflate.so</p>
<p style="padding-left: 30px;">AddOutputFilterByType DEFLATE text/html text/plain text/xml</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/php-http-clients-and-on-the-fly-gzip-compression..html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Auto Upgrade and SFTP</title>
		<link>http://www.raditha.com/blog/archives/wordpress-auto-upgrade-and-sftp.html</link>
		<comments>http://www.raditha.com/blog/archives/wordpress-auto-upgrade-and-sftp.html#comments</comments>
		<pubDate>Tue, 30 Jun 2009 05:40:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/wordpress-auto-upgrade-and-sftp.html</guid>
		<description><![CDATA[Wordpress added a nice feature a while back &#8211; the ability to upgrade your installation while logged into the admin console. If you make use of this feature you no longer need to mess around with downloading zip file, deleting the old stuff, loading the upgrade.php script etc etc. The same system can be used [...]]]></description>
			<content:encoded><![CDATA[<p>Wordpress added a nice feature a while back &#8211; the ability to upgrade your installation while logged into the admin console. If you make use of this feature you no longer need to mess around with downloading zip file, deleting the old stuff, loading the upgrade.php script etc etc. The same system can be used to upgrade plugins too.</p>
<p>I never made use of this feature for two reasons, the first being that my wordpress installation is <a href="http://www.raditha.com/blog/archives/subversioned-wordpress-upgrade.html">subversioned</a> (revision control with subversion) and the second being that only FTP and FTP+SSL were supported by it. FTP+SSL isn&#8217;t so bad but <a href="http://www.raditha.com/php/ftp/security.php">FTP is totally insecure</a>. Eventually I decided to use this update system for the plugins at least and thought I should  add support for SFTP. The plan was to create a plugin that would add an SSH option to the upgrader. It was then that I found that SFTP support is already there but hasn&#8217;t been enabled!</p>
<img title="Hey wheres the SSH" src="http://www.raditha.com/blog/images/wp-nossh.jpg" alt="no SSH" />
<p>On my desktop computer (Fedora 11), where I keep a copy of all my websites, I had the SFTP option enabled in a less than a minute but on my production server it took a while longer. That was because because libssh2, which is the key requirement for the PHP SSH extension could not be installed with YUM. (This is <a href="http://www.raditha.com/blog/archives/001056.html">a Centos server</a>). While attempting to use YUM, I had to run a load of updates and worst of all reboot the server (something which hasn&#8217;t been done for more than an year).</p>
<p>libssh2/php ssh extention had to be installed manually and I followed the instructions in the /wp-admin/includes/class-wp-filesystem-ssh2.php file &#8211; the same set of instructions are found at <a href="http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/">http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/</a>. Unfortunately they both contain an error.</p>
<p style="padding-left: 30px;">cd /usr/src<br />
wget http://surfnet.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.14.tar.gz<br />
tar -zxvf libssh2-0.14.tar.gz<br />
cd libssh2-0.14/<br />
./configure<br />
make all install</p>
<p>The libssh2 download is really ancient &#8211; it wouldn&#8217;t even compile on my Centos box &#8211; worse gcc even segfaulted while trying to compile it. I kid you not. I have never seen gcc segfault before.</p>
<p style="padding-left: 30px;"><span style="color: #993300;">make[1]: Entering directory `/root/libssh2-0.14/src&#8217;<br />
gcc -o channel.o channel.c -c -g -O2 /usr/include -I/usr/include -Wall -I../include/ -fPIC<br />
gcc: /usr/include: linker input file unused because linking not done<br />
channel.c:1253:10: /usr/include: No such file or directory<br />
channel.c:71: internal compiler error: Segmentation fault<br />
Please submit a full bug report,<br />
with preprocessed source if appropriate.<br />
See  for instructions.<br />
make[1]: *** [channel.o] Error 1<br />
make[1]: Leaving directory `/root/libssh2-0.14/src&#8217;<br />
make: *** [all] Error 1</span></p>
<p style="padding-left: 30px;">
<p><span style="color: #993300;"><span style="color: #000000;"> The correct way to go about it is to visit the <a href="http://sourceforge.net/projects/libssh2">libssh2 project page on sourceforge </a> and download the latest version (happens to be 1.1 at the time of writing).  The latest version could be compiled without any problems. After that you can do the pecl installation followed by editing the php.ini file<br />
</span></span></p>
<p style="padding-left: 30px;">pecl install -f ssh2</p>
<div class="wp-caption aligncenter" style="width: 587px"><img title="ssh , there it is " src="http://www.raditha.com/blog/images/wp-ssh.jpg" alt="wordpress and ssh"  /><p class="wp-caption-text">wordpress and ssh</p></div>
<p>In my case, I had to give the full path to the ssh2.so file because the engine couldn&#8217;t find the extension when only a relative path was given. That&#8217;s because pear seems to have installed the shared object at a wierd location. Well in the end after the apachectl restart I now have the PHP SSH extension enabled and wordpress update page does show the ssh2 extension.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/wordpress-auto-upgrade-and-sftp.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Readfile vs Include, echo vs print; don&#8217;t bother</title>
		<link>http://www.raditha.com/blog/archives/readfile-vs-include-echo-vs-print-dont-bother.html</link>
		<comments>http://www.raditha.com/blog/archives/readfile-vs-include-echo-vs-print-dont-bother.html#comments</comments>
		<pubDate>Mon, 29 Jun 2009 05:57:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[religion]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/readfile-vs-include-echo-vs-print-dont-bother.html</guid>
		<description><![CDATA[There is a post at http://code.google.com/speed/articles/optimizing-php.html by one of Google&#8217;s webmasters giving out several tips on how to optimize PHP scripts. Most of it is complete baloney and has been debunked by Gwynne Raskind at http://groups.google.com/group/make-the-web-faster/browse_thread/thread/ddfbe82dd80408cc. What some people will do in the name of optimizing code is absolutely ridiculous. At most they will save [...]]]></description>
			<content:encoded><![CDATA[<p>There is a post at <a href="http://code.google.com/speed/articles/optimizing-php.html">http://code.google.com/speed/articles/optimizing-php.html</a> by one of Google&#8217;s webmasters giving out several tips on how to optimize PHP scripts. Most of it is complete baloney and has been debunked by Gwynne Raskind at <a href="http://groups.google.com/group/make-the-web-faster/browse_thread/thread/ddfbe82dd80408cc">http://groups.google.com/group/make-the-web-faster/browse_thread/thread/ddfbe82dd80408cc</a>. What some people will do in the name of optimizing code is absolutely ridiculous. At most they will save a thousandth of a second after putting in 2 days of effort. Here is the proof : <a href="http://raditha.com/wiki/Php_optimize">Should you optimize PHP?</a> and <a href="http://raditha.com/wiki/Readfile_vs_include">Readfile vs Include</a></p>
<p>Both these articles were written quite a few years ago and Interestingly I have received a handful of hate mail from people who spend all their time optimizing code!</p>
<p>If you want your code to execute fast, design a good algorithm or better still look one up in a book. There is no substitute for it. If your app is connected to a database make sure it&#8217;s properly designed. If you are retrieving data from a remote server use a cache. All this applies not just to PHP but to any language on any platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/readfile-vs-include-echo-vs-print-dont-bother.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Subversioned Wordpress Upgrade</title>
		<link>http://www.raditha.com/blog/archives/subversioned-wordpress-upgrade.html</link>
		<comments>http://www.raditha.com/blog/archives/subversioned-wordpress-upgrade.html#comments</comments>
		<pubDate>Wed, 04 Mar 2009 03:50:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[etc]]></category>
		<category><![CDATA[Collaboration]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/subversioned-wordpress-upgrade.html</guid>
		<description><![CDATA[They say, release early, release often and Wordpress is one software that seems to follow that mantra pretty well. Fortunately upgrading from one version of Wordpress to another is a painless task &#8211; unless of course you have a customized installation. Upgrading a customized installation can be made easier if you use subversion.
Normally, in order [...]]]></description>
			<content:encoded><![CDATA[<p>They say, release early, release often and Wordpress is one software that seems to follow that mantra pretty well. Fortunately upgrading from one version of Wordpress to another is a painless task &#8211; unless of course you have a customized installation. Upgrading a customized installation can be made easier if you use subversion.</p>
<p>Normally, in order to upgrade, all you need to do is to delete the old stuff, copy over the set of scripts from the new version and invoke upgrade.php . But if you recursively delete all the old stuff you lose your version control info. So this is my approach to upgrading a customized WP installation which has been subversioned.</p>
<p>1) copy the files that you have modified into a safe place (themes and plugins will make up the bulk of this)</p>
<p>2) Download wordpress and unzip it, then change into the source directory and use rsync to copy over the new files while deleting obsolete files from the previous version. the &#8211;exclude &#8216;.svn&#8217; part will ensure that subversion info is not discard. If you are using another revision control system, you can use the appropriate directory here</p>
<p>rsync . /var/www/raditha/blog/ -avz &#8211;exclude &#8216;.svn&#8217; &#8211;delete</p>
<p>3) Then add new files into the repository with</p>
<p>svn add `svn stat | grep &#8216;^\?&#8217; | cut -d&#8217; &#8216; -f8`</p>
<p>4) copy back the themes and plugins (inclusive of the .svn folders).</p>
<p>4) delete the obsolete ones with:</p>
<p>svn rm `svn stat | grep &#8216;^\!&#8217; | cut -d&#8217; &#8216; -f7`</p>
<p>5) Merging &#8211; unfortunately there is no easy recipe for this, you need to manually Kompare , Meld or diff the files to see if your code needs to be merged.</p>
<p>6) commit.</p>
<p>7) run upgrade.php</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/subversioned-wordpress-upgrade.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WordPress Performance and GZip.</title>
		<link>http://www.raditha.com/blog/archives/wordpress-performance-and-gzip..html</link>
		<comments>http://www.raditha.com/blog/archives/wordpress-performance-and-gzip..html#comments</comments>
		<pubDate>Fri, 16 Jan 2009 01:40:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/wordpress-performance-and-gzip..html</guid>
		<description><![CDATA[Everyone loves wordpress and everyone hates it&#8217;s poor performance. The reason that it is so slow is because half a dozen mysql queries are executed for each fragment of a blog post that it displays. So I thought of trying to compress the wp_posts table to find out if it has any impact on performance [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone loves wordpress and everyone hates it&#8217;s poor performance. The reason that it is so slow is because half a dozen mysql queries are executed for each fragment of a blog post that it displays. So I thought of trying to compress the wp_posts table to find out if it has any impact on performance but before doing that, the speed without compression has to be measured. Here is a typical result (when tested with httperf)</p>
<div style="margin: auto; overflow: auto; height: 100px; margin-bottom:10px">
<pre>httperf --hog --client=0/1 --server=radmedia --port=80 --uri=/blog/ --send-buffer=4096 --recv-buffer=16384 --num-conns=50 --num-calls=1
Maximum connect burst length: 1

Total: connections 50 requests 50 replies 50 test-duration 11.002 s

Connection rate: 4.5 conn/s (220.0 ms/conn, &lt;=1 concurrent connections)
Connection time [ms]: min 213.1 avg 220.0 max 358.2 median 217.5 stddev 20.1
Connection time [ms]: connect 0.3
Connection length [replies/conn]: 1.000

Request rate: 4.5 req/s (220.0 ms/req)
Request size [B]: 66.0

Reply rate [replies/s]: min 4.4 avg 4.5 max 4.6 stddev 0.1 (2 samples)
Reply time [ms]: response 160.5 transfer 59.2
Reply size [B]: header 245.0 content 22111.0 footer 2.0 (total 22358.0)
Reply status: 1xx=0 2xx=50 3xx=0 4xx=0 5xx=0

CPU time [s]: user 2.67 system 8.16 (user 24.2% system 74.2% total 98.4%)
Net I/O: 99.5 KB/s (0.8*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0</pre>
</div>
<p>I tested several times and too the mean which is exactly the same as the one produced by the above test : a very poor 4.5 requests per second. You can see just how bad this really is by using httperf to retrieve a static page on the same site.</p>
<div style="margin: auto; overflow: auto; height: 100px; margin-bottom:10px">
<pre>httperf --hog --client=0/1 --server=radmedia --port=80 --uri=/blog.html --send-buffer=4096 --recv-buffer=16384 --num-conns=50 --num-calls=1
Maximum connect burst length: 1

Total: connections 50 requests 50 replies 50 test-duration 0.111 s

Connection rate: 450.9 conn/s (2.2 ms/conn, &lt;=1 concurrent connections)
Connection time [ms]: min 1.3 avg 2.2 max 41.2 median 1.5 stddev 5.6
Connection time [ms]: connect 0.3
Connection length [replies/conn]: 1.000

Request rate: 450.9 req/s (2.2 ms/req)
Request size [B]: 70.0

Reply rate [replies/s]: min 0.0 avg 0.0 max 0.0 stddev 0.0 (0 samples)
Reply time [ms]: response 0.5 transfer 1.5
Reply size [B]: header 274.0 content 22111.0 footer 0.0 (total 22385.0)
Reply status: 1xx=0 2xx=50 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.02 system 0.09 (user 19.8% system 80.2% total 100.1%)
Net I/O: 9887.7 KB/s (81.0*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0</pre>
</div>
<p>For this test, I used wget to download the blog main page and copied the resultant HTML back on the server. That way, I had an piece of static HTML that is exactly the same as the blog main page. Again, what&#8217;s produced is a typical result the mean turned out to be 447 connections a second. Yes your eyes do not lie. There is a hundred fold difference in performance.</p>
<p>Now I compressed the wp_posts table using a few lines of PHP code and added a plugin with a &#8216;posts_results&#8217; filter to decompress it again. Here is a typical load test report:</p>
<div style="margin: auto; overflow: auto; height: 100px; margin-bottom:10px">
<pre>httperf --hog --client=0/1 --server=radmedia --port=80 --uri=/blog/ --send-buffer=4096 --recv-buffer=16384 --num-conns=50 --num-calls=1
Maximum connect burst length: 1

Total: connections 50 requests 50 replies 50 test-duration 10.990 s

Connection rate: 4.5 conn/s (219.8 ms/conn, &lt;=1 concurrent connections)
Connection time [ms]: min 213.4 avg 219.8 max 231.6 median 219.5 stddev 4.2
Connection time [ms]: connect 0.3
Connection length [replies/conn]: 1.000

Request rate: 4.5 req/s (219.8 ms/req)
Request size [B]: 66.0

Reply rate [replies/s]: min 4.4 avg 4.5 max 4.6 stddev 0.1 (2 samples)
Reply time [ms]: response 159.8 transfer 59.7
Reply size [B]: header 245.0 content 22110.0 footer 2.0 (total 22357.0)
Reply status: 1xx=0 2xx=50 3xx=0 4xx=0 5xx=0

CPU time [s]: user 2.63 system 8.18 (user 23.9% system 74.4% total 98.4%)
Net I/O: 99.6 KB/s (0.8*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0</pre>
</div>
<p>As you can see there isn&#8217;t much of a difference. Compression of the wp_posts table doesn&#8217;t lead to any change in the number of average requests per second it&#8217;s stil 4.5</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/wordpress-performance-and-gzip..html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LAN Speed Test</title>
		<link>http://www.raditha.com/blog/archives/1791.html</link>
		<comments>http://www.raditha.com/blog/archives/1791.html#comments</comments>
		<pubDate>Mon, 05 Jan 2009 14:27:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[etc]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1791</guid>
		<description><![CDATA[
What you see here is a speed test carried out using a free tool by Speedtest.net. It&#8217;s rather predictably named as speedtest mini. At first glance these results are impressive it shows that I have a very fast Local Area Network (184 mbps down and 277 mbps up) but it&#8217;s a lie. I do have [...]]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344" data="http://www.youtube.com/v/y9RarK2wUHE&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/y9RarK2wUHE&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
<p>What you see here is a speed test carried out using a free tool by <a href="http://www.speedtest.net">Speedtest.net</a>. It&#8217;s rather predictably named as speedtest mini. At first glance these results are impressive it shows that I have a very fast Local Area Network (184 mbps down and 277 mbps up) but it&#8217;s a lie. I do have a very fast LAN but this figure is a huge understatement. My LAN is faster. Much much faster. I have gigabite ethernet and the actual speed is at least three times the speed that&#8217;s reported.</p>
<p>The result is inaccurate because the test method isn&#8217;t very scientific. It works by downloading several large files from the web server ( in my case hosted on a server in the LAN). File access is limited by the speed of the hard drives. Unfortunately most hard drives cannot deliver at 100 mbps &#8211; the upper limit for gigabit ethernet. <a href="http://www.raditha.com/linux/drive-speed.php">Hard drives operate much slower</a>.</p>
<p>For broadband speedtest which is what most people use the tool for &#8211; the hard drives will not act as a bottleneck because broadband links typically operate at much much slower speeds and will not place an undue burden on the hard drives (even if multiple users are trying the test concurrently).</p>
<p>For the upload test, the widget POSTs some data to the server. The data appears to be generated internally or it&#8217;s uploading a file that it just cached into memory. The result is that the hard drive bottleneck doesn&#8217;t play such a significant role  &#8211; at least not for smaller uploads which are held in memory at the server rather than being saved to disk. And speed test doesn&#8217;t try to upload a lot of data at once anyway because most servers are not equipped to handle a large incoming upload (see this link if you want to learn how to configure your server : <a href="http://www.radinks.com/upload/config.php">http://www.radinks.com/upload/config.php</a></p>
<p>So how do I know that my LAN really is as fast I as I claim it to be. I used this simple PHP scripts (which mimics a 128MB file being downloaded to test it out)</p>
<p>$s=&#8221;0&#8243;;</p>
<p>for($i = 0 ; $i &lt; 16 ; $i++)<br />
{<br />
$s .= $s;<br />
}</p>
<p>for($i = 0 ; $i &lt; 2048 ; $i++)<br />
{<br />
echo $s;<br />
}<br />
?&gt;</p>
<p>And this is what wget reported:</p>
<p>Saving to: `nofile.php&#8217;</p>
<p>[       &lt;=&gt;                                                                                                         ] 67,108,864  52.2M/s   in 1.2s</p>
<p>2009-01-04 14:45:13 (52.2 MB/s) &#8211; `nofile.php&#8217; saved [67108864]</p>
<p>52.2 MB/s that&#8217;s already three times as fast as what speedtest reports but this is not accurate either. That&#8217;s because wget is still saving the file to the local drive (which again acts as the bottleneck). Even that can be avoided by redirecting output to /dev/null/</p>
<p>wget http://radmedia/speedtest/nofile.php -O /dev/null</p>
<p>That gives a slightly faster result<br />
Saving to: `/dev/null&#8217;</p>
<p>[          &lt;=&gt;                                                                                                      ] 134,219,776 69.0M/s   in 1.9s</p>
<p>2009-01-04 14:56:25 (69.0 MB/s) &#8211; `/dev/null&#8217; saved [134219776]</p>
<p>This result seems a lot more realistic. Yet I am disapointed that it&#8217;s not close to the 100 MB/s mark which his about the max that you can get with gigabit ether. Do I have so much of noise in my cable to wipe off about 30% of the bandwidth?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1791.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bye Bye Wiki</title>
		<link>http://www.raditha.com/blog/archives/bye-bye-wiki.html</link>
		<comments>http://www.raditha.com/blog/archives/bye-bye-wiki.html#comments</comments>
		<pubDate>Tue, 09 Dec 2008 01:30:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[web 0.8]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/archives/bye-bye-wiki.html</guid>
		<description><![CDATA[I have been having a Wiki on this site at http://www.raditha.com/wiki/ for nearly four years but was finally forced to take it down because I couldn&#8217;t keep pace with the spam bots. The last straw came when I ran into the following error while trying to clean up after the vandals.
Database error
A database query syntax [...]]]></description>
			<content:encoded><![CDATA[<p>I have been having a Wiki on this site at <a href="http://www.raditha.com/wiki/">http://www.raditha.com/wiki/</a> for nearly four years but was finally forced to take it down because I couldn&#8217;t keep pace with the spam bots. The last straw came when I ran into the following error while trying to clean up after the vandals.</p>
<h3 style="padding-left: 30px;"><span style="color: #330000;">Database error</span></h3>
<p style="padding-left: 30px;"><span style="color: #330000;">A database query syntax error has occurred. This could be because of an illegal search query (see <a title="Raditha.com:Searching" href="../../wiki/Raditha.com:Searching">Searching Raditha.com</a>), or it may indicate a bug in the software. The last attempted database query was:</span></p>
<blockquote style="padding-left: 30px;"><p><span style="color: #330000;"><tt>INSERT INTO archive (ar_namespace,ar_title,ar_text,ar_comment,ar_user,ar_user_text,ar_timestamp,ar_minor_edit,ar_flags) SELECT cur_namespace,cur_title,cur_text,cur_comment,cur_user,cur_user_text,cur_timestamp,cur_minor_edit,0 FROM cur WHERE cur_namespace=3 AND cur_title='Alis'</tt></span></p></blockquote>
<p style="padding-left: 30px;"><span style="color: #330000;">from within function &#8220;<tt>Article::doDeleteArticle</tt>&#8220;. MySQL returned error &#8220;<tt>1114: The table 'archive' is full</tt>&#8220;.</span></p>
<div class="printfooter"></div>
<p>There has been so much spam over the last few years that the MySQL table is full. I was tempted to clean up the database, update the mediawiki software used to power the wiki and start all over but then realized that it&#8217;s a lot of hard work for little return.</p>
<p>During the early days, there were a few usefull contributions to the wiki but later on they were inundated by spam. Nearly every legit contribution was accidentally deleted while cleaning up spam. Some pages would be hit even 40-50 times a minute (no wonder the database filled up). I tried combating it by using the mediawiki block list and IPtables. Entire subnets were filtered out to no avail. The spam kept increased and never showed signs of decreasing.</p>
<p>Trouble might have been averted if I had kept mediawiki upto date but that didn&#8217;t happen. Unlike most CMS style web applications it&#8217;s not possible to &#8217;skip versions with mediawiki&#8217;. Well it might be possible now but it wasn&#8217;t always so. That means if you can&#8217;t keep up with all their new releases, it becomes harder and hard to do the update. I gave up years ago.</p>
<p>In the end I just relied on wget and a small python script that I wrote to convert all the wiki entries into PHP. There are only a few (too few really, yeah pathetically few if you would call a spade a spade) pages which means all the time and effort spent on it is just a waste.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/bye-bye-wiki.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing HTML with Python.</title>
		<link>http://www.raditha.com/blog/archives/1763.html</link>
		<comments>http://www.raditha.com/blog/archives/1763.html#comments</comments>
		<pubDate>Mon, 08 Dec 2008 01:08:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[etc]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1763</guid>
		<description><![CDATA[Needed to make a small change to my photoblog &#8211; a change that should be reflected on every single post.  Thought I might be able to use python DOM to get it done. With PHP it&#8217;s quite easy, I have done that sort of thing many times in the past.
Can&#8217;t that be handled by the [...]]]></description>
			<content:encoded><![CDATA[<p>Needed to make a small change to my <a href="http://photos.raditha.com">photoblog</a> &#8211; a change that should be reflected on every single post.  Thought I might be able to use python DOM to get it done. With PHP it&#8217;s quite easy, I have done that sort of thing many times in the past.</p>
<p>Can&#8217;t that be handled by the template? no because this was a CSS change that really did involve changing the post&#8217;s HTML.  It was just a matter of removing an inline style (CSS) and replacing it with a CSS class. But each post only has a fragment so python minidom simply refused parse it. That forced me to look at HTMLParser which I didn&#8217;t like because it&#8217;s an old fashion event driven parser. There was a time when use to swear by event driven parsers (expat for example) but that was long ago.</p>
<p>Thus I had no option but to revert to the minidom API and to make my HTML fragment well formed by adding a new start and end tag to enclose the whole fragment. These enclosing tags can be stripped out later when I am saving the modified post back to the database.</p>
<p>With this approach the code is short and sweet. But of course I need to flesh it out by adding support for retrieving posts from the database and writing them back in, instead of working with the hardcoded bit of HTML as done during testing.</p>
<p style="padding-left: 30px;">#!/usr/bin/python</p>
<p style="padding-left: 30px;">from xml.dom.minidom import *</p>
<p style="padding-left: 30px;">domNode = parseString(&#8216;&lt;xml&gt;&lt;p align=&#8221;center&#8221;&gt;&lt;a href=&#8221;/images/comingup.jpg&#8221;&gt;&lt;img src=&#8221;/images/comingup-t.jpg&#8221; title=&#8221;dawn&#8221; alt=&#8221;Sunrise close to Nuwara Eliya&#8221; style=&#8221;border-color: #505050; border-width: 7px&#8221; /&gt;&lt;/a&gt;&lt;/p&gt;Great Western, Nuwara Eliya at Dawn.&lt;/xml&gt;&#8217;)</p>
<p style="padding-left: 30px;">ele = domNode.getElementsByTagName(&#8216;img&#8217;)<br />
ele.item(0).removeAttribute(&#8217;style&#8217;)<br />
ele.item(0).setAttribute(&#8220;class&#8221;,&#8221;photo&#8221;);</p>
<p style="padding-left: 30px;">subNode = domNode.firstChild;</p>
<p style="padding-left: 30px;">if subNode.hasChildNodes():<br />
children = subNode.childNodes<br />
for child in children:<br />
print child.toxml()</p>
<p style="padding-left: 30px;">
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1763.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Religion</title>
		<link>http://www.raditha.com/blog/archives/1949.html</link>
		<comments>http://www.raditha.com/blog/archives/1949.html#comments</comments>
		<pubDate>Fri, 28 Nov 2008 14:46:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[religion]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1949</guid>
		<description><![CDATA[You might have noticed that I have an item named religion in my tag cloud. Does that mean I have suddenly become religious? Hello no. Exorcise that thought. Religion is the opium of the poor (well I am not exactly rich but I am not poor and don&#8217;t do opium). Heaven and hell exists only [...]]]></description>
			<content:encoded><![CDATA[<p>You might have noticed that I have an item named religion in my tag cloud. Does that mean I have suddenly become religious? Hello no. Exorcise that thought. Religion is the opium of the poor (well I am not exactly rich but I am not poor and don&#8217;t do opium). Heaven and hell exists only in the minds of preachers.</p>
<p>Lots of other geeks are religious though. They would swear by Java, PHP or some poor souls who need to be rescued even swear by primitive things like C# or .NET (windows really does sucks (No that has nothing to do with religion , it&#8217;s a scientific fact)).</p>
<p>So this tag, religion is about such arguments like &#8216;<a href="http://www.raditha.com/blog/archives/001204.html">PHP is better than Java</a>&#8216; and &#8216;perl is better than python&#8217; (anyone want to compare <a href="http://www.raditha.com/blog/archives/001723.html">Fortran and Python</a>?).</p>
<p>Well what&#8217;s really better, is it PHP or Java? well it&#8217;s a matter of horses for courses (but PHP has recently lost the plot a bit with an API that is way too big, but then Java is showing it&#8217;s age too).<br />
While still on the subject of religion and religious wars you might ask, Is <a href="http://www.raditha.com/blog/archives/001449.html">Fedora better than Debian</a>?  Yes Fedora is miles ahead of Debian (but even so, Debian is much better than Windows)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1949.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Netbeans 6.5 and PHP</title>
		<link>http://www.raditha.com/blog/archives/1962.html</link>
		<comments>http://www.raditha.com/blog/archives/1962.html#comments</comments>
		<pubDate>Sun, 16 Nov 2008 01:05:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1962</guid>
		<description><![CDATA[Been waiting for a long time for PHP support to be added into Netbeans. Decided that I can wait no longer and downloaded the nightly build. And what can I say, I just love it.
Netbeans can be used with Xdebug to debug PHP scripts. I know that xdebug can be used with eclipse too but [...]]]></description>
			<content:encoded><![CDATA[<p>Been waiting for a long time for PHP support to be added into Netbeans. Decided that I can wait no longer and downloaded the nightly build. And what can I say, I just love it.</p>
<p>Netbeans can be used with Xdebug to debug PHP scripts. I know that xdebug can be used with eclipse too but I have never quite aquired a taste for eclipse. Of course which IDE is better is largely a matter of religious preference but in my humble opion the best IDE is Nebeans.</p>
<p>I am no longer a heavy PHP coder, so I use whatever editor that comes to mind when I actually do write in PHP &#8211; many of them don&#8217;t even have debug support. But Netbeans is something that is almost always on my desktop so this means I can do both PHP and Java on the same IDE.</p>
<p>Footnote: install xdebug with <em>yum install php-pecl-xdebug</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1962.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python or Ratsnake?</title>
		<link>http://www.raditha.com/blog/archives/1723.html</link>
		<comments>http://www.raditha.com/blog/archives/1723.html#comments</comments>
		<pubDate>Mon, 03 Nov 2008 21:19:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[religion]]></category>
		<category><![CDATA[weird]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1723</guid>
		<description><![CDATA[So is this language a Python or a Ratsnake? Actually Rat snakes are very harmless species of non venomous snakes. As the name suggests they eat rats and mice so if you see one slithering into your house you shouldn&#8217;t chase it away. They are always welcome into mine. I spotted one in the store [...]]]></description>
			<content:encoded><![CDATA[<p>So is this language a Python or a Ratsnake? Actually Rat snakes are very harmless species of non venomous snakes. As the name suggests they eat rats and mice so if you see one slithering into your house you shouldn&#8217;t chase it away. They are always welcome into mine. I spotted one in the store room about a month back.</p>
<p>As for python, it doesn&#8217;t even have block quotes! Well people tell me that I don&#8217;t need block quotes, and unlike ratsnakes, blockquotes are poison. Since Pythons aren&#8217;t venomous the don&#8217;t go together. That makes Python similar to Fortran and perl. Perl has other useful features not present in python, like the <em>here document</em>. But when you look closer you find that triple quotes can be used as a substitute. I know python fans will fall on my like a bunch of Anacondas for <a href="http://www.raditha.com/blog/archives/001611.html">comparing python with Fortran</a>. They seem to hate it.</p>
<p>One great advantage of PHP is that is dynamical typed which means a great disadvantage of PHP and of Python is that they are both dynamically typed (no I am not contradicting myself it&#8217;s great when things go right, a huge pain when things go wrong). PHP has several functions to sort out the types mess but sometimes they give strange results.</p>
<p>I have seen programming language quizzes where they give you an expression with mixed types and ask you what the result is going to be. How stupid is that? No self respecting programmer is going to bother to figure out such code in his head.</p>
<p>I digress. The whole point of this was because of the trouble I was having finding the equivalent of print_r or var_dump of PHP in python. It was after some searching that I found it on a <a href="http://www.wooblelab.com/command/show/127">wierdly named site</a> the function is repr. Who ever came up with that name?</p>
<p>I had more difficulty in finding the size of an uploaded file &#8211; sure, I know how to get the size after the file has been saved &#8211; but I need to know the size before saving &#8211; so far, the documentation hasn&#8217;t thrown up anything. Sure you can get the size indirectly by us calling len() on the file data but it seems such a waste.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1723.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHProjekt</title>
		<link>http://www.raditha.com/blog/archives/1782.html</link>
		<comments>http://www.raditha.com/blog/archives/1782.html#comments</comments>
		<pubDate>Mon, 03 Nov 2008 06:56:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Collaboration]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1782</guid>
		<description><![CDATA[I first ran Into PHProjekt around 8-9 years ago when I myself was working for a groupware and messaging solution provider. At the time PHProjekt to put it rather bluntly, was half baked. We had our own project management software and it was worse. When the plug was finally pulled on it, no one mourned [...]]]></description>
			<content:encoded><![CDATA[<p>I first ran Into <a href="http://www.phprojekt.com/">PHProjekt</a> around 8-9 years ago when I myself was working for a groupware and messaging solution provider. At the time PHProjekt to put it rather bluntly, was half baked. We had our own project management software and it was worse. When the plug was finally pulled on it, no one mourned it&#8217;s demise.</p>
<p>PHPProjekt on the other hand has survived and has seen the release of many new versions. While so much of features have been added it hasn&#8217;t become any easier to use. Memories have faded but I think it&#8217;s actually a lot harder to use now than it was then.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1782.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trying to Find a Fool Proof Way of Changing Permalinks</title>
		<link>http://www.raditha.com/blog/archives/1698.html</link>
		<comments>http://www.raditha.com/blog/archives/1698.html#comments</comments>
		<pubDate>Thu, 30 Oct 2008 04:25:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1698</guid>
		<description><![CDATA[The other day, I changed the permalinks structure in my photo blog. I wasn&#8217;t getting a lot of traffic  there, so I wasn&#8217;t too worried about things going wrong. Well, they did go wrong. I used dean&#8217;s permalink migration plugin (because it was the one recommended in a couple of articles I read on the [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I changed the permalinks structure in my <a href="http://photos.raditha.com">photo blog</a>. I wasn&#8217;t getting a lot of traffic  there, so I wasn&#8217;t too worried about things going wrong. Well, they did go wrong. I used dean&#8217;s permalink migration plugin (because it was the one recommended in a couple of articles I read on the topic)  to redirect the old links to the new ones. The plugin worked marvelously well for individual entries, but it couldn&#8217;t handle the monthly archives and I had to <a href="http://www.raditha.com/blog/archives/001629.html">modify the .htaccess</a> file to include a couple of rewrite rules to redirect those links manually.</p>
<p>For this blog, I don&#8217;t want the old entries to be redirected at all. The old links should remain the way they are (numeric) and the new ones should have the title in the link. That&#8217;s because many old posts are ranked high in google. Changing their URLs might result in them dropping off.</p>
<p>At first I thought of writing my own plug-in oto achieve this but a good geek doesn&#8217;t write anything if he can avoid it. So I looked around again and found the <a href="http://urbangiraffe.com/plugins/advanced-permalinks/">advanced permalinks</a> migration plugin which at first sight seemed to do the job just right.</p>
<p>On closer inspection I found that the category archives broke the moment the plugin was enabled. Great pity because it has just the features that I am looking for and the author seems to have put in a lot of effort for it. However it&#8217;s said to be compatible with wordpress version 2.50 or older and the current version is 2.63. So there you are, it doesn&#8217;t always pay to be lazy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1698.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Putting the fun back into blogging.</title>
		<link>http://www.raditha.com/blog/archives/1667.html</link>
		<comments>http://www.raditha.com/blog/archives/1667.html#comments</comments>
		<pubDate>Thu, 23 Oct 2008 14:59:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1667</guid>
		<description><![CDATA[Ever since switching from movable type to wordpress, I have been posting like mad. That in spite of my rather busy schedule. In fact I am busier now than I was about 2-3 months ago when I barely manged 2 posts a week. Heck I have an exam coming up in 10 days time and [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since <a href="/blog/archives/001484.html">switching from movable type to wordpress</a>, I have been posting like mad. That in spite of my rather busy schedule. In fact I am busier now than I was about 2-3 months ago when I barely manged 2 posts a week. Heck I have an exam coming up in 10 days time and haven&#8217;t even started reading. Over the past few weeks, I have blogged almost on a daily basis &#8211; on top of that I have 14 drafts waiting to be published!</p>
<p>That probably goes to show that wordpress really is fun to use while MT isn&#8217;t. But I will not be too critical, it served me well for more than 3 years specially at a time when my expectations of a blogger was very different. Movable type itself has changed, they are now more keen to target business bloggers rather than individual geeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1667.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing the Wordpress Permalinks Migration Plugin</title>
		<link>http://www.raditha.com/blog/archives/1629.html</link>
		<comments>http://www.raditha.com/blog/archives/1629.html#comments</comments>
		<pubDate>Wed, 22 Oct 2008 23:26:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1629</guid>
		<description><![CDATA[The other day, I changed the wordpress permalinks structure on my photo blog. Once you make the change, incoming links on other sites, google search and even internal links will result in 404 errors because wordpress will no longer map your old permalinks to individual posts. You can fix it by using Dean Lee&#8217;s permalink [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, I changed the wordpress permalinks structure on my photo blog. Once you make the change, incoming links on other sites, google search and even internal links will result in 404 errors because wordpress will no longer map your old permalinks to individual posts. You can fix it by using Dean Lee&#8217;s permalink <a href="http://www.deanlee.cn/wordpress/permalinks-migration-plugin/">migration plugin</a>.</p>
<p>That takes care of single posts but unfortunately the plugin doesn&#8217;t work with monthly archives. In my <a href="http://photos.raditha.com/">photo blog</a>, the permalink format was &#8216;numeric&#8217; (/archives/%post_id%) which results in the montly archives looking like this: <a href="http://photos.raditha.com/archives/date/2008/01">http://photos.raditha.com/archives/date/2008/01</a> . Under the new &#8216;postname&#8217; scheme that I adopted ( /archives/%postname%/ ) the link becomes <a href="http://photos.raditha.com/archives/2008/01">http://photos.raditha.com/archives/2008/01</a> &#8211; idealy Dean&#8217;s plugin should redirect the old archives page to the new one but it doesn&#8217;t happen. However if you do click on the links above <em>you will</em> find that the redirection does indeed work. That&#8217;s only because I have changed my .htaccess file to rewrite them. The .htaccess file now looks like this:</p>
<div style="overflow: auto; padding-left: 30px; height: 100px; color: #000033;">&lt;IfModule mod_rewrite.c&gt;<br />
#Alias /archives/date /archives<br />
RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_URI} archives/date/(.*)<br />
RewriteRule archives/date/(.*) archives/$1 [R=302,N]</p>
<p>RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
RewriteCond %{REQUEST_URI} !archives/date/(.*)</p>
<p>RewriteRule . /index.php [L]<br />
&lt;/IfModule&gt;</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1629.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Wordpress: Change Permalinks</title>
		<link>http://www.raditha.com/blog/archives/1626.html</link>
		<comments>http://www.raditha.com/blog/archives/1626.html#comments</comments>
		<pubDate>Mon, 20 Oct 2008 16:27:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1626</guid>
		<description><![CDATA[At my photoblog, I don&#8217;t get as much traffic as I should. The reason is that the posts are identified by their postid ( /%post_id%/ ). As a result the urls are not keyword heavy and get lower rank. You will struggle to find any of those posts coming up top for any search.
It&#8217;s better [...]]]></description>
			<content:encoded><![CDATA[<p>At my <a href="http://photos.raditha.com">photoblog</a>, I don&#8217;t get as much traffic as I should. The reason is that the posts are identified by their postid ( /%post_id%/ ). As a result the urls are not keyword heavy and get lower rank. You will struggle to find any of those posts coming up top for any search.</p>
<p>It&#8217;s better to have posts identified by their names ( /%postname%/ ). I decided to go ahead and take the plunge and make the switch. Changing wordpress permalinks is a piece of cake. With the more recent versions you don&#8217;t even have to edit your .htaccess file to switch from one kind of permalink structure to another. But there is a catch: what happens to the links that are already there and have been indexed by the spiders? They will now generate 404 errors.</p>
<p>I was sure there would be at least one plugin that can translate the old URLs into the new scheme. If the worst comes to worst, I thougt I could just create a few URL rewrite rules to take care of it. But there was a plugin that can translate the urls. It&#8217;s named <a href="http://www.deanlee.cn/">Dean&#8217;s Permalink Migration</a> plugin and it looks like it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1626.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RTFM causes 500 internal server error</title>
		<link>http://www.raditha.com/blog/archives/1606.html</link>
		<comments>http://www.raditha.com/blog/archives/1606.html#comments</comments>
		<pubDate>Sun, 19 Oct 2008 00:00:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[weird]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1606</guid>
		<description><![CDATA[I can never quite remember whether it&#8217;s print_r or var_dump in PHP that can send a detailed dump of an object to the server log file.  Who wants to remember it anyway, that&#8217;s what the manual is there for. I want the manual to be instantly available, so I have a local copy. It&#8217;s been [...]]]></description>
			<content:encoded><![CDATA[<p>I can never quite remember whether it&#8217;s print_r or var_dump in PHP that can send a detailed dump of an object to the server log file.  Who wants to remember it anyway, that&#8217;s what the manual is there for. I want the manual to be instantly available, so I have a local copy. It&#8217;s been working fine so for many years. What can go wrong with static HTML after all? Something did go wrong a few days ago.</p>
<p>When I tried to read the documentation on <em>variable functions</em>. I get an internal server error. The (local) link that caused the error was:</p>
<p style="padding-left: 60px;">http://localhost/php5.2/intro.var.html</p>
<p>And the detailed message in the apache error log was:</p>
<p style="padding-left: 30px;">Syntax error in type map, no &#8216;:&#8217; in /var/www/html/php5.2/intro.var.html for header &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;\n, referer: http://localhost/php5.2/refs.basic.vartype.html</p>
<p>I reckoned I could sort this out by commenting out the following line in the httpd.conf file.</p>
<p style="padding-left: 30px;">#AddHandler type-map var</p>
<p>For good measure, I commented out a few other settings that control type mappings &#8211; the web server is being confused by the filename containing a .var in it (please see link above).</p>
<p style="padding-left: 30px;">&lt;Directory &#8220;/var/www/error&#8221;&gt;<br />
#        AllowOverride None<br />
#        Options IncludesNoExec<br />
#        AddOutputFilter Includes html<br />
#        AddHandler type-map var<br />
#        Order allow,deny<br />
#        Allow from all<br />
#        LanguagePriority en es de fr<br />
#        ForceLanguagePriority Prefer Fallback<br />
&lt;/Directory&gt;</p>
<p>and lastly. &#8216;<em>DirectoryIndex index.html index.html.var</em>&#8216; became just &#8216;<em>DirectoryIndex index.html</em>&#8216;. After wards apache was restarted and I am merrily on my way. So what if the apache default page is now broken? That&#8217;s only seen when there is configured website.</p>
<p>That fixes that but a couple of days later I ran into another error: <a href="http://www.raditha.com/blog/archives/001613.html">subrequested from r-&gt;uri</a><br />
Oh and by the way, it&#8217;s print_r that can send the dump to the log file instead of the browser, not var_dump</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1606.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Photo Blog Updated to WP 2.6</title>
		<link>http://www.raditha.com/blog/archives/1507.html</link>
		<comments>http://www.raditha.com/blog/archives/1507.html#comments</comments>
		<pubDate>Thu, 25 Sep 2008 04:32:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.raditha.com/blog/?p=1507</guid>
		<description><![CDATA[Soon after moving this blog from Movable Type to Wordpress, I decided to update by photo blog also to wordpress 2.6.2 This upgrade really was a piece of cake and was finished in less than 2 minutes &#8211; most of those two minutes were taken by by rsyncing template changes.
]]></description>
			<content:encoded><![CDATA[<p>Soon after moving this blog from Movable Type to Wordpress, I decided to update by <a href="http://photos.raditha.com">photo blog</a> also to wordpress 2.6.2 This upgrade really was a piece of cake and was finished in less than 2 minutes &#8211; most of those two minutes were taken by by rsyncing template changes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1507.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP5 XSLT on Debian.</title>
		<link>http://www.raditha.com/blog/archives/1450.html</link>
		<comments>http://www.raditha.com/blog/archives/1450.html#comments</comments>
		<pubDate>Fri, 15 Aug 2008 01:29:24 +0000</pubDate>
		<dc:creator>raditha</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://raditha/blog/?p=644</guid>
		<description><![CDATA[Another side effect of using the unstable repo to install FF3 was that it messed up my apache. Debian does advice against using the unstable repo. That means it really isn&#8217;t suited for anyone who wants to use the latest version of any software. There is a long gap between Debian releases and at that [...]]]></description>
			<content:encoded><![CDATA[<p>Another side effect of using the unstable repo to install FF3 was that it messed up my apache. Debian does advice against using the unstable repo. That means it really isn&#8217;t suited for anyone who wants to use the latest version of any software. There is a long gap between Debian releases and at that rate we will have to wait forever to see FF3 make it&#8217;s way into the stable repository. That means there is no choice but to go with the unstable option.</p>
<p>I sorted out the apache issue by uninstalling and reinstalling it. Things went smoothly for a couple of days, until I needed to run an old PHP script. The script is nothing special it just does a bit of XSL transformation. It makes use of the PHP XSLT extension. The trouble is that is not part of debian!!</p>
<p>There is a PHP4-XSLT module and there is a PHP5-XSL module but no PHP5-XSLT how anoying. Once upon a long ago, I quite used to enjoy compiling things from source but now I am too old forit. Nevertheless it seems that I have no choice but to manually compile PHP5. I didn&#8217;t get far &#8211; the PHP configuration script came up with this ridiculous statement</p>
<div style="margin-left:15px; color:#330000">
<pre>checking whether the C compiler (gcc  ) works... no
configure: error: installation or configuration problem: C compiler cannot create executables.</pre>
</div>
<p>Turns out this is because libc6-dev is not installed. That is easily rectified but while installing libc6-dev, apt decided to uninstall xorg? how ridiculous is that. Looks like I will be limited to the terminal next time I reboot the machine.</p>
<p>But when I tried to compile PHP again, I ran into the same error once more. Close inspection reveals that APT had choked out with</p>
<div style="margin-left:15px; color:#330000">
<pre>Failed to fetch http://ftp2.jp.debian.org/debian/pool/main/g/glibc/libc6-dev_2.7-12_i386.deb</pre>
</div>
<p>How anoying is that? when Fedora 10 is released, I am definitely switching back.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1450.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pythogorean triplets</title>
		<link>http://www.raditha.com/blog/archives/1218.html</link>
		<comments>http://www.raditha.com/blog/archives/1218.html#comments</comments>
		<pubDate>Wed, 30 May 2007 22:43:09 +0000</pubDate>
		<dc:creator>raditha</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://raditha/blog/?p=554</guid>
		<description><![CDATA[We all know of the Pythagorean theorem (Well if you don&#8217;t know that one, you probably stumbled to the wrong place, there wouldn&#8217;t be anything of interest to you here).
A Pythogorean triplet is the set of three integers that figure in the equation. At Project Euler, the 9th problem is to find a triplet so [...]]]></description>
			<content:encoded><![CDATA[<p>We all know of the Pythagorean theorem (Well if you don&#8217;t know that one, you probably stumbled to the wrong place, there wouldn&#8217;t be anything of interest to you here).</p>
<p>A Pythogorean triplet is the set of three integers that figure in the equation. At <a href="http://projecteuler.net/index.php?section=problems&amp;id=9">Project Euler</a>, the 9th problem is to find a triplet so that a+b+c = 1000</p>
<p>It&#8217;s not the most difficult problem listed there.</p>
<div style="color:#330000; margin-left:20px">
<pre>for($a=0 ; $a &lt; 1000 ; $a++)
{
for($b = 0 ; $b &lt; 1000 ; $b++)
{
$c2 = pow($a,2) + pow($b,2);
$c = sqrt($c2);
//echo "$a, $b, $c \n";
if(ceil($c) == floor($c))
{
// int
if(($a+$b+$c)== 1000)
{
echo "MATCH for $a, $b, $c | product = " . ($a*$b*$c) ."\n";

}
}
}
}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.raditha.com/blog/archives/1218.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: www.raditha.com @ 2010-07-31 09:35:48 -->