<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Hardcoded</title>
	<atom:link href="http://moisadoru.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://moisadoru.wordpress.com</link>
	<description>free(DOM);</description>
	<lastBuildDate>Sat, 02 Apr 2011 08:23:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='moisadoru.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Hardcoded</title>
		<link>http://moisadoru.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://moisadoru.wordpress.com/osd.xml" title="Hardcoded" />
	<atom:link rel='hub' href='http://moisadoru.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Static call versus Singleton call in PHP</title>
		<link>http://moisadoru.wordpress.com/2010/03/02/static-call-versus-singleton-call-in-php/</link>
		<comments>http://moisadoru.wordpress.com/2010/03/02/static-call-versus-singleton-call-in-php/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 01:39:58 +0000</pubDate>
		<dc:creator>Doru Moisa</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[singleton]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://moisadoru.wordpress.com/?p=89</guid>
		<description><![CDATA[Introduction In the past several months I&#8217;ve been working with a rather large application built with symfony. I noticed that symfony makes heavy use of the Singleton pattern (other frameworks, like Zend do that too); everywhere in the code there were pieces like this one: &#60;?php // ... sfSomething::getInstance(); // ... ?&#62; I know that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=89&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Introduction</h3>
<p>In the past several months I&#8217;ve been working with a rather large application built with symfony. I noticed that symfony makes heavy use of the Singleton pattern (other frameworks, like Zend do that too); everywhere in the code there were pieces like this one:</p>
<pre style="padding-left:30px;"><span style="color:#993300;">&lt;?php
// ...
sfSomething::getInstance();
// ...
?&gt;</span></pre>
<p>I know that in more than half of the situations, you can write your code using plain static classes, with some initialize() method, as an alternative to writing singletons. For example, this is a dummy Singleton:</p>
<pre style="padding-left:60px;"><span style="color:#993300;">&lt;?php
class DummySingleton {
    private function __construct(){}
    private function __clone(){}
    public static function getInstance(){
        if(self::$__instance == NULL) self::$__instance = new DummySingleton;
        return self::$__instance;
    }
    public function foo(){
        echo 'I am DummySingleton::foo()';
    }
}
?&gt;</span></pre>
<p>Now this is a completely useless class, but it suits our purpose of illustrating the Singleton. Notice the amount of code needed by the Singleton pattern. Except the foo() method, all the code in the class makes sure you have only one instance at any time during the execution.</p>
<p>Now let&#8217;s write a static class that does the same thing as the Singleton:</p>
<pre style="padding-left:30px;"><span style="color:#993300;">&lt;?php
class DummyStatic {
    static public function foo(){
        echo 'I am DummyStatic::foo()';
    }
}
?&gt;
</span></pre>
<p>This is much cleaner, as we don&#8217;t need the extra code the Singleton needs, and can focus on our task at hand.</p>
<h3>Performance comparison</h3>
<p>Let&#8217;s compare the performance of the two approaches. I&#8217;ve written a small test script that looks like this:</p>
<pre style="padding-left:30px;"><span style="color:#993300;">&lt;?php

/**
* A singleton class
*/
class TestSingleton {
    // singleton code
    private static $__instance = NULL;
    private function __construct(){}
    private function __clone(){}
    static public function getInstance(){
        if(self::$__instance == NULL) self::$__instance = new TestSingleton;
        return self::$__instance;
    }

    // our actual code
    public $val = 0;
    public function test(){
        for($i=0;$i&lt;30;$i++) $this-&gt;val += $i;
    }
}</span></pre>
<pre style="padding-left:30px;"><span style="color:#993300;">
/**
* a plain static class (all members are static)
*/
class TestStatic {
    static public $val = 0;
    static public function test(){
        for($i=0;$i&lt;30;$i++) self::$val += $i;
    }
}</span></pre>
<pre style="padding-left:30px;"><span style="color:#993300;">
// how many runs
$runs = 500000;</span></pre>
<pre style="padding-left:30px;"><span style="color:#993300;">
// benchmarking Singleton
$start = microtime(TRUE);
for($i=0;$i&lt;$runs;$i++) TestSingleton::getInstance()-&gt;test();
$run1 = microtime(TRUE) - $start;</span></pre>
<pre style="padding-left:30px;"><span style="color:#993300;">
// benchmarking static
$start = microtime(TRUE);
for($i=0;$i&lt;$runs;$i++) TestStatic::test();
$run2 = microtime(TRUE) - $start;

echo '&lt;pre&gt;';
echo 'test singleton: '.number_format($run1, 8)." s\n";
echo 'test static:    '.number_format($run2, 8).' s';</span><span style="color:#993300;">
?&gt;</span>
</pre>
<p>Basicly, I put together the two types of classes. Both have a method called test(), which does some arithmetic operations, just to have something that spends some execution time.</p>
<p>I&#8217;ve ran this script for various values for the $runs variable: 100, 1k 10k, 100k, 200k, 300k, 500k and 1M.</p>
<h3>Test results</h3>
<table style="height:184px;" width="393">
<thead>
<tr>
<td>Number of runs</td>
<td>Singleton call time (s)</td>
<td>Static call time (s)</td>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>0.004005</td>
<td>0.001511</td>
</tr>
<tr>
<td>1,000</td>
<td>0.018872</td>
<td>0.014552</td>
</tr>
<tr>
<td>10,000</td>
<td>0.174744</td>
<td>0.141820</td>
</tr>
<tr>
<td>100,000</td>
<td>1.643465</td>
<td>1.431564</td>
</tr>
<tr>
<td>200,000</td>
<td>3.277334</td>
<td>2.812432</td>
</tr>
<tr>
<td>300,000</td>
<td>5.079388</td>
<td>4.419048</td>
</tr>
<tr>
<td>500,000</td>
<td>8.086555</td>
<td>6.841494</td>
</tr>
<tr>
<td>1,000,000</td>
<td>16.189018</td>
<td>13.696728</td>
</tr>
</tbody>
</table>
<p>I have also done some spreadsheet magic, and generated this chart:</p>
<p><img class="alignnone size-full wp-image-94" style="border:1px solid black;margin:6px;" title="PHP_Singleton_vs_Static" src="http://moisadoru.files.wordpress.com/2010/03/php_singleton_vs_static.png?w=693&#038;h=529" alt="" width="693" height="529" /></p>
<p>As you can see, for a relatively small number of runs (&lt;1k), the Static code is significantly faster than the Singleton, an than it stabilizes arround 15% faster than Singleton, as I expected. This is because every function/method call involves some operations (symbol lookup, stack manipulation etc.), and each call to the Singleton method, in fact, also calls the getInstance() static method.</p>
<h3>Conclusion</h3>
<p>It may not be that obvious that making extensive use of Singletons has this kind of side effect; however, if your code has more that 100 or 1,000 calls to some getInstance() method of a Singleton class, you might want to consider caching the reference to the object it returns, or even refactoring the code to use only static method calls.</p>
<p>You might say that you need an object because you do stuff in the constructor. That can be easily achieved with some kind of static initialize() method, that should be called once in your code, just before usage. If you have some auto loading mechanism in place, you could call it just after loading the class, for example, if you want to automate the initialization process. But keep in mind that this is not a 100% replacement for Singletons; you need an object if you want to serialize/unserialize it (for caching, some RPC call, etc.).</p>
<h3>Update.</h3>
<p>Tested with <a title="HPHP Homepage" href="http://wiki.github.com/facebook/hiphop-php" target="_blank">Facebook&#8217;s HPHP compiler:</a></p>
<p>I&#8217;ve tested the script using the HPHP compiler, and the results are spectacular. While keeping the same time ratio between the Singleton and Static calls, what stroke me is the huge difference (<span style="color:#333399;"><strong>HPHP is ~ 200 times faster</strong></span>):</p>
<p><!--   		BODY,DIV,TABLE,THEAD,TBODY,TFOOT,TR,TH,TD,P { font-family:"Arial"; font-size:x-small } --></p>
<table border="0" cellspacing="0" rules="NONE">
<col width="119"></col>
<col width="137"></col>
<col width="136"></col>
<col width="143"></col>
<col width="149"></col>
<tbody>
<tr>
<td rowspan="2" width="119" height="34" align="CENTER" valign="MIDDLE"><strong>Number of calls</strong></td>
<td colspan="2" width="274" align="CENTER" valign="MIDDLE"><strong>Time spent (Apache)</strong></td>
<td colspan="2" width="291" align="CENTER" valign="MIDDLE"><strong>Time spent (HPHP)</strong></td>
</tr>
<tr>
<td align="CENTER">Apache Singleton call</td>
<td align="CENTER">Apache Static call</td>
<td align="CENTER">HPHP Singleton call</td>
<td align="CENTER">HPHP Static call</td>
</tr>
<tr>
<td height="17" align="LEFT">100</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.004005</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.001511</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00001502</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00000906</span></td>
</tr>
<tr>
<td height="17" align="LEFT">1,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.018872</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.014552</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00008988</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00007486</span></td>
</tr>
<tr>
<td height="17" align="LEFT">10,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.174744</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.141820</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00075102</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00063801</span></td>
</tr>
<tr>
<td height="17" align="LEFT">100,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">1.643465</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">1.431564</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00829983</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.00795388</span></td>
</tr>
<tr>
<td height="17" align="LEFT">200,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">3.277334</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">2.812432</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.01839614</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.01339102</span></td>
</tr>
<tr>
<td height="17" align="LEFT">300,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">5.079388</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">4.419048</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.02502608</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.01932502</span></td>
</tr>
<tr>
<td height="17" align="LEFT">500,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">8.086555</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">6.841494</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.04114008</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.03280401</span></td>
</tr>
<tr>
<td height="17" align="LEFT">1,000,000</td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">16.189018</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">13.696728</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.07872796</span></td>
<td align="RIGHT"><span style="font-family:Cumberland AMT,Cumberland,Courier New,Liberation Mono,Nimbus Mono L,DejaVu Sans Mono,Courier,Lucida Sans Typewriter,Lucida Typewriter,Monaco,Monospaced;">0.06373119</span></td>
</tr>
</tbody>
</table>
<p>Happy coding.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moisadoru.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moisadoru.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/moisadoru.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/moisadoru.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moisadoru.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moisadoru.wordpress.com/89/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moisadoru.wordpress.com/89/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moisadoru.wordpress.com/89/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=89&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://moisadoru.wordpress.com/2010/03/02/static-call-versus-singleton-call-in-php/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/757d86c17937ce92fc3df001444ae12b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Doru Moisa</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2010/03/php_singleton_vs_static.png" medium="image">
			<media:title type="html">PHP_Singleton_vs_Static</media:title>
		</media:content>
	</item>
		<item>
		<title>Apache 2 PHP module version switcher for Debian/Ubuntu (2)</title>
		<link>http://moisadoru.wordpress.com/2009/08/24/apache-2-php-module-version-switcher-for-debianubuntu-2/</link>
		<comments>http://moisadoru.wordpress.com/2009/08/24/apache-2-php-module-version-switcher-for-debianubuntu-2/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 22:26:40 +0000</pubDate>
		<dc:creator>Doru Moisa</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://moisadoru.wordpress.com/?p=76</guid>
		<description><![CDATA[An easy to use PHP 5/6 switch script, part 2<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=76&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello again,</p>
<p>I decided to continue <a href="http://moisadoru.wordpress.com/2009/08/19/apache-2-php-module-version-switcher-for-debian-ubuntu/">my little experiment</a> with <a href="http://www.php.net">PHP</a> and <a href="http://httpd.apache.org">Apache 2</a>, and installed <a href="http://www.php.net/releases/5_3_0.php">PHP 5.3.0</a>, so that I could enjoy thinks like closures, namespaces and so on, without having to cope with PHP6&#8242;s state of development and with it&#8217;s bugs. I compiled it from source, using this command:</p>
<p><code><em><span style="color:#800000;">./configure --with-apxs2=/usr/bin/apxs2 --with-mysql --prefix=/opt/php53  --with-regex --with-libxml-dir=/usr/lib --with-openssl=/usr/lib --with-pcre-regex --with-curl --enable-exif --with-gd --enable-gd-native-ttf --with-gettext --with-mhash --with-imap --with-imap-ssl --enable-mbstring --with-mcrypt --with-mssql --with-mysql --with-mysqli --enable-pcntl --with-pspell --with-libedit --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --with-xmlrpc --with-xsl --with-openssl=/usr --with-kerberos --enable-embedded-mysqli=shared --with-pdo-mysql=shared --enable-shared=yes --with-interbase=no --with-oci8=no --with-adabas=no --with-pdo-firebird=no --with-pdo-oci=no --with-pdo-odbc=no --with-pgsql=no --with-pdo-mysql --with-pdo-pgsql=no --with-recode=no --with-snmp=no --with-sybase-ct=no</span><br />
</em></code></p>
<p><strong>Later edit: </strong></p>
<p><strong>After that run make. Before running sudo make install, please backup the /usr/lib/apache2/modules/libphp5.so file, because it will get overwritten by the install command. After running make install, rename the /usr/lib/apache2/mobules/libphp5.so file to libphp53.so, and copy back the backuped version of libphp5.so.</strong></p>
<p><strong>After that, I created the php53.load and php53.conf files in the /etc/apache2/mods-available/ folder (copy the contents of php5.conf and php5.load and modify the LoadModule directive to include libphp53.so instead of libphp5.so)</strong>, and updated my shell script to consider this version too. Also, so it happend that I was reading some RSS feeds about some changes in <a href="http://www.ubuntu.com">Ubuntu 9.10</a> (Karmic Koala), and decided to add some eye candy to the script, that is <a href="https://wiki.ubuntu.com/NotifyOSD">notify-osd</a>. Notify-osd is the program that makes those nice notification bubbles that was introduced in Ubuntu 9.04. I installed the libnotify-bin package, played a little and came up with this version of the apapche-php script:</p>
<pre><code><span style="color:#800000;">#!/bin/bash

php5="/etc/apache2/mods-enabled/php5.load"
php53="/etc/apache2/mods-enabled/php53.load"
php6="/etc/apache2/mods-enabled/php6.load"
apache="/var/run/apache2.pid"
old=""

if [ -e "$php5" ]
then
    old="php5"
    enabled5="TRUE"
else
    enabled5="FALSE"
fi
if [ -e "$php53" ]
then
    old="php53"
    enabled53="TRUE"
else
    enabled53="FALSE"
fi

if [ -e "$php6" ]
then
    old="php6"
    enabled6="TRUE"
else
    enabled6="FALSE"
fi

if [ -e "$apache" ]
then
    running="started"
    op="/etc/init.d/apache2 restart"
else
    running="stopped"
    op="/etc/init.d/apache2 start"
fi

echo "5$enabled5"
echo "6$enabled6"

run=$(zenity --title "Switch PHP version"  --list  \
 --text "Apache ($running) with PHP 5/6" --radiolist\
 --column "Active" --column "run" --column "Version" --hide-column=2 \
"$enabled5" "php5" "Apache 2 with PHP 5.2.10" \
"$enabled53" "php53" "Apache 2 with PHP 5.3.0" \
"$enabled6" "php6" "Apache 2 with PHP 6-DEV" \
);

if [ -z $run ]
then
    exit
fi

if [ $run != $old ]
then
    a2enmod $run
    a2dismod $old
fi
$op | zenity --progress --pulsate --auto-kill --auto-close --title "Applying changes ...."

sleep 1

phpversion=""
if [ "php5" == "$run" ]
then
    phpversion="5.2.10"
else
    if [ "php53" == "$run"  ]
    then
	phpversion="5.3.0"
    else
	if [ "php6" == "$run" ]
	then
	    phpversion="6.0.0-DEV"
	fi
    fi
fi

if [ -e "$apache" ]
then
    notify-send "Apache 2 with PHP $phpversion" "Changes applied and server restarted succesfully" -i dialog-info -u normal
    #zenity --info --text "Changes applied"
else
    notify-send "Apache 2" "An error occured, please check the Apache log file for details" -i dialog-error -u critical
    #zenity --error --text "An error occured, check the apache log"
fi</span></code></pre>
<p>When you run this (with gksudo of course), it displays this list:</p>
<p><img class="alignnone size-full wp-image-77" title="Screenshot-Switch PHP version" src="http://moisadoru.files.wordpress.com/2009/08/screenshot-switch-php-version.png?w=300&#038;h=196" alt="Screenshot-Switch PHP version" width="300" height="196" /></p>
<p>After checking the version you want, it will display a progress dialog, wait one second and then, the notification daemon will display this bubble on success:</p>
<p><img class="alignnone size-full wp-image-78" title="apache-notify-ok" src="http://moisadoru.files.wordpress.com/2009/08/apache-notify-ok.png?w=537&#038;h=155" alt="apache-notify-ok" width="537" height="155" /></p>
<p>&#8230; or this one on failure:</p>
<p><img class="alignnone size-full wp-image-79" title="apache-notify-error" src="http://moisadoru.files.wordpress.com/2009/08/apache-notify-error.png?w=537&#038;h=155" alt="apache-notify-error" width="537" height="155" /></p>
<p>Enjoy !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moisadoru.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moisadoru.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/moisadoru.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/moisadoru.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moisadoru.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moisadoru.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moisadoru.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moisadoru.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=76&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://moisadoru.wordpress.com/2009/08/24/apache-2-php-module-version-switcher-for-debianubuntu-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/757d86c17937ce92fc3df001444ae12b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Doru Moisa</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/screenshot-switch-php-version.png" medium="image">
			<media:title type="html">Screenshot-Switch PHP version</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/apache-notify-ok.png" medium="image">
			<media:title type="html">apache-notify-ok</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/apache-notify-error.png" medium="image">
			<media:title type="html">apache-notify-error</media:title>
		</media:content>
	</item>
		<item>
		<title>Apache 2 PHP module version switcher for Debian/Ubuntu</title>
		<link>http://moisadoru.wordpress.com/2009/08/19/apache-2-php-module-version-switcher-for-debian-ubuntu/</link>
		<comments>http://moisadoru.wordpress.com/2009/08/19/apache-2-php-module-version-switcher-for-debian-ubuntu/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 00:37:43 +0000</pubDate>
		<dc:creator>Doru Moisa</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[php6]]></category>

		<guid isPermaLink="false">http://moisadoru.wordpress.com/?p=63</guid>
		<description><![CDATA[An easy to use PHP 5/6 switch script.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=63&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Update, see <a href="http://moisadoru.wordpress.com/2009/08/24/apache-2-php-module-version-switcher-for-debianubuntu-2/">the part 2, also starring PHP 5.3</a> !</strong></p>
<p>One of these days I thought of trying out a snapshot of the current development version of <a href="http://php.net">PHP</a>&#8216;s next major version, <a href="http://snaps.php.net/">PHP 6</a>. I&#8217;m using an alpha version of <a href="http://www.ubuntu.com">Ubuntu</a> (Karmik <a href="http://www.ubuntu.com/testing/karmic/alpha3">alpha3</a>), which behaves very nicely, and I thought to go all the way with this and try a dev version of PHP.</p>
<p>After installing some of the dependencies needed to compile PHP (dev versions of various system libraries and build tools), and tying <a href="http://bugs.php.net/bug.php?id=49270" target="_blank">without any luck</a> to compile a tar.gz snapshot of PHP 6, I checked out the sources from <a href="http://www.php.net/svn.php">SVN</a>, and got it working. After much trial and error, I succeeded using this configure command:</p>
<p style="text-align:left;"><span style="color:#800000;"><code><em>./configure --with-apxs2=/usr/bin/apxs2 --with-mysql --prefix=/opt/php6 --with-regex --with-libxml-dir=/usr/lib --with-openssl=/usr/lib --with-pcre-regex --with-curl --enable-exif --with-gd --enable-gd-native-ttf --with-gettext --with-mhash --with-imap --with-imap-ssl --enable-mbstring --with-mcrypt --with-mssql --with-mysql --with-mysqli --enable-pcntl --with-pspell --with-libedit --with-readline --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --with-xmlrpc --with-xsl --with-openssl=/usr --with-kerberos --enable-embedded-mysqli=shared --with-pdo-mysql=shared --enable-shared=yes --with-fbsql=no --with-interbase=no --with-oci8=no --with-adabas=no --with-pdo-firebird=no --with-pdo-oci=no --with-pdo-odbc=no --with-pgsql=no --with-pdo-pgsql=no --with-recode=no --with-snmp=no --with-sybase-ct=no --enable-debug</em></code></span></p>
<p>After that, make and sudo make install. During the make install command, the script complained about httpd.conf not containig any LoadModule section. In Debian and Debian based distros, like Ubuntu, the Apache settings are split over multiple files. Every apache module has a .conf and a .load file in /etc/apache2/mods-available.</p>
<p>The .load file contains the specific LoadModule directive, and the .conf file contains module specific configurations. The reason for this is to make it simpler to activate/deactivate a specific module using the a2enmod and a2dismod commands, which create or destroy symlinks for the .conf and .load files from /etc/apache2/mods-available to /etc/apache2/mods-enabled. During Apache&#8217;s startup, it loads any .load files in the mods-available folder, then it loads any .conf files in the same folder.</p>
<p>I added a dummy LoadModule line in httpd.conf, and ran make install again. After that I took the LoadModule line injected by the install script into httpd.conf and put it in a file called php6.load in the mods-available folder, and reverted httpd.conf to the initial state (an empty file). Also I created a php.ini file in /opt/php6/lib/.</p>
<p>Then I disabled the php5 module with<code><br />
<em><span style="color:#800000;"> </span></em></code></p>
<p><code><em><span style="color:#800000;">sudo a2dismod php5 &amp;&amp; sudo a2enmode php6 &amp;&amp; sudo /etc/init.d/apache2 restart</span></em><br />
</code></p>
<p>and tested a phpinfo page. It worked <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and I was happy.</p>
<p>But as I tested some of my apps in PHP6, I ran into <a href="http://bugs.php.net/bug.php?id=49273">some trouble</a> and wrote this little script to help me easily switch between PHP versions to use when I&#8217;m researching or when I&#8217;m working. It uses a little program called <a href="http://live.gnome.org/Zenity">zenity</a>, which display all sorts of configurable GUI elements on the screen. Here it is:</p>
<pre><span style="color:#800000;"><code>
#!/bin/bash

php5="/etc/apache2/mods-enabled/php5.load"
php6="/etc/apache2/mods-enabled/php6.load"
apache="/var/run/apache2.pid"
old=""

if [ -e "$php5" ]
then
    old="php5"
    enabled5="TRUE"
else
    enabled5="FALSE"
fi

if [ -e "$php6" ]
then
    old="php6"
    enabled6="TRUE"
else
    enabled6="FALSE"
fi

if [ -e "$apache" ]
then
    running="started"
    op="/etc/init.d/apache2 restart"
else
    running="stopped"
    op="/etc/init.d/apache2 start"
fi

run=$(zenity --title "Switch PHP version"  --list  --text "Apache ($running) with PHP 5/6" --radiolist \
--column "Active" --column "run" --column "Version" --hide-column=2 \
"$enabled5" "php5" "Apache with PHP 5" \
"$enabled6" "php6" "Apache with PHP 6-DEV" \
);

if [ -z $run ]
then
    exit
fi

if [ $run != $old ]
then
    a2enmod $run
    a2dismod $old
fi
$op | zenity --progress --pulsate --auto-kill --auto-close --title "Applying changes ...."

sleep 1

if [ -e "$apache" ]
then
    zenity --info --text "Changes applied"
else
  </code></span><span style="color:#800000;"><code>  zenity --error --text "An error occured, check the apache log"
fi
</code></span></pre>
<p>I put this one in /opt/bin (this is the place where I put experimental stuff ) and called it apache-php (had a lack of imagination on the name). I also made a shortcut with a nice icon, so I can access it easily. Please note that you must run the script with gksudo, eg. &#8220;gksudo /opt/bin/apache-php&#8221;, because you need to be root to modify any settings in the  /etc folder (or any system folder for that matter).</p>
<p>What this script does, is this; it looks for the php5.load and php6.load files in the mods-enabled folder, and displays a nice zenity dialog with the one enabled already selected, like the one in this picture</p>
<p><img class="alignnone size-full wp-image-64" title="Switch-PHP-version-select" src="http://moisadoru.files.wordpress.com/2009/08/switch-php-version-select.png?w=300&#038;h=196" alt="Switch-PHP-version-select" width="300" height="196" /></p>
<p>After selecting the desired PHP version, and you hit OK, a progress dialog appears for a short while, while the changes are being made:</p>
<p><img class="alignnone size-full wp-image-65" title="Applying" src="http://moisadoru.files.wordpress.com/2009/08/applying.png?w=200&#038;h=108" alt="Applying" width="200" height="108" /></p>
<p>and then, on completion a simple alert that informs of the completion of the process:</p>
<p><img class="alignnone size-full wp-image-66" title="done" src="http://moisadoru.files.wordpress.com/2009/08/done.png?w=192&#038;h=125" alt="done" width="192" height="125" /></p>
<p>The script waits for Apache to restart, then waits one second and the checks for the Apache pid file ( /var/run/apache2.pid ). If the file is not there, it means that something went wrong, and an error box like this one is displayed;</p>
<p><img class="alignnone size-full wp-image-67" title="Error" src="http://moisadoru.files.wordpress.com/2009/08/error.png?w=349&#038;h=137" alt="Error" width="349" height="137" /></p>
<p>Usually this should not happend, but if it does, something went wrong, and you have to check the Apache logs to find it.</p>
<p>I know that there are<a href="http://www.gentoo-wiki.info/HOWTO_PHP5_and_PHP6_Simultaneously"> methods for running PHP5 and PHP6 in the same time</a>, one as an Apache module and the other as FastCGI, but it adds unneeded complexity, and you can&#8217;t use the same file extension with both, which, in my humble oppinion, is not the proper way to use and test PHP6.</p>
<p>I hope this helps people who use different versions of PHP and like to switch version with a click. With a little imagination and tweaking, you could transform this script into a more complex one, for, let&#8217;s say enable and disable different Apache modules, or add more PHP versions, etc.</p>
<p>I encourage you to compile PHP 6 and try it, and <a href="http://bugs.php.net/">report bugs</a> back to the development team, because, besides letting them know that you&#8217;re interested in their work, you help them find bugs and fix them. Also, check <a href="http://www.php.net/~scoates/unicode/render_func_data.php">this page</a> for progress in the Unicode compatibility of different PHP functions and extensions.</p>
<p>Happy coding and compiling folks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moisadoru.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moisadoru.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/moisadoru.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/moisadoru.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moisadoru.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moisadoru.wordpress.com/63/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moisadoru.wordpress.com/63/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moisadoru.wordpress.com/63/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=63&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://moisadoru.wordpress.com/2009/08/19/apache-2-php-module-version-switcher-for-debian-ubuntu/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/757d86c17937ce92fc3df001444ae12b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Doru Moisa</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/switch-php-version-select.png" medium="image">
			<media:title type="html">Switch-PHP-version-select</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/applying.png" medium="image">
			<media:title type="html">Applying</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/done.png" medium="image">
			<media:title type="html">done</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/08/error.png" medium="image">
			<media:title type="html">Error</media:title>
		</media:content>
	</item>
		<item>
		<title>Maxmind Geoip module for Kohana</title>
		<link>http://moisadoru.wordpress.com/2009/02/20/maxmindgeoip-module-for-kohana/</link>
		<comments>http://moisadoru.wordpress.com/2009/02/20/maxmindgeoip-module-for-kohana/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 05:19:13 +0000</pubDate>
		<dc:creator>Doru Moisa</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[geoip]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[maxmind]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://blog.doru.homeunix.org/?p=23</guid>
		<description><![CDATA[It&#8217;s a little Kohana module I wrote. You can find it here: http://projects.kohanaphp.com/projects/show/geoip More info here.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=23&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="text-align:left;">It&#8217;s a little <a href="http://kohanaphp.com" target="_blank">Kohana</a> module I wrote.</p>
<p style="text-align:left;">You can find it here: <a href="http://projects.kohanaphp.com/projects/show/geoip" target="_blank">http://projects.kohanaphp.com/projects/show/geoip</a></p>
<p>More info <a title="Readme file" href="http://projects.kohanaphp.com/documents/3" target="_blank">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moisadoru.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moisadoru.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/moisadoru.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/moisadoru.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moisadoru.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moisadoru.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moisadoru.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moisadoru.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=23&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://moisadoru.wordpress.com/2009/02/20/maxmindgeoip-module-for-kohana/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/757d86c17937ce92fc3df001444ae12b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Doru Moisa</media:title>
		</media:content>
	</item>
		<item>
		<title>Home-baked SVN support for Komodo Edit</title>
		<link>http://moisadoru.wordpress.com/2009/02/12/home-baked-svn-support-for-komodo-edit/</link>
		<comments>http://moisadoru.wordpress.com/2009/02/12/home-baked-svn-support-for-komodo-edit/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 23:05:56 +0000</pubDate>
		<dc:creator>Doru Moisa</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[komodo]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.doru.homeunix.org/?p=1</guid>
		<description><![CDATA[Komodo Edit (version 5.0.3 5.1.4 at the time of this writing) is my tool of choice for code editing. It is built on top of Mozilla and Scintilla with some Python glue, which gives it great flexibility (Firefox like extensions, custom lexer files etc.) I am using Komodo Edit for web development, mainly PHP/HTML/Javascript on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=1&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.activestate.com/komodo_edit/" target="_blank">Komodo Edit</a> (version <span style="text-decoration:line-through;">5.0.3</span> <a title="Komodo Edit downloads" href="http://downloads.activestate.com/Komodo/releases/5.1.4/" target="_blank">5.1.4</a> at the time of this writing) is my tool of choice for code editing. It is built on top of Mozilla and Scintilla with some Python glue, which gives it great flexibility (Firefox like extensions, custom lexer files etc.)</p>
<p>I am using Komodo Edit for web development, mainly PHP/HTML/Javascript on Ubuntu Intrepid 64bit, and I must say that I&#8217;m extremely satisfied with my setup. It is extremely fast and clutter free.</p>
<p><a href="http://www.activestate.com" target="_blank">ActiveState</a> has done a lot of work in making this great tool. They also have a commercial product that extends the editor with some pretty neat pieces of functionality (<a href="http://www.activestate.com/komodo/" target="_blank">Komodo IDE</a>). I also tried the IDE, but for my specific needs I&#8217;m sattisfied with the free version. I&#8217;m considering buying a licence for the IDE in the future.</p>
<p>There are a couple of notable differences between the two &#8220;dragons&#8221;, most important are the ability to handle version control systems and debuggers from within the IDE, but not from within the free edition.</p>
<p>Of course, there are other alternatives like <a href="http://www.aptana.com" target="_blank">Aptana</a>, which is also a great tool (I&#8217;ve been using it for a while), but I don&#8217;t like having JRE installed if possible (less dependencies is better). I also like to be a little different, and give other products a fair chance to be used. It&#8217;s a matter of personal taste I guess. Other IDE&#8217;s offer integrated database editing tools. I use MySQL as the db layer on most of my projects, but I don&#8217;t actually need that into my code editor. I use MySQL Administrator, Query Browser and Workbench, and I&#8217;m pretty satisfied by those tools. It also allows me to concetrate on the specific part of the application (database design, database debug, code editing) without having all that functionality loaded into my editor all the time.</p>
<p>Now, returning to Komodo Edit, one thing that is not easy to do, is to work with a versioned local copy of a project. You have to keep a terminal window opened all the time, and fire some, let&#8217;s say,  <strong><code>svn commit</code></strong>,  <strong><code>svn add</code></strong> or <strong><code>svn update</code></strong> every time you modify something.</p>
<p>Subversion is widely used as a version control system, and it is available for all kinds of unix/linux flavours, mac, windows etc. We&#8217;re going to get rid of the terminal window and customize Komodo to do simple operations like commit or update.</p>
<p>How are going to do that? Well, one of the greatest things that Komodo offers is the possibility to add your own pieces of functionality into it, by using macros, snippets, commands, menus, toolbars etc. We&#8217;re going to create a toolbar and a couple of buttons that trigger some subversion commands. We already have subversion installed (we were using it from the command line, remember ?), so there are no other prerequisites required for our task. The advantage is that we rely solely on the official subversion binaries available to our system, which takes the weight of keeping it updated off our backs, as opposed to let&#8217;s say when we have our own subversion library and need to keep it updated.</p>
<p>This guide is for Linux only. It should also work in unix/mac os x. It does not work in windows, because windows lacks some system tools like awk or grep.</p>
<p>First, we make the right panel visible, and rightclick on the Samples <span style="text-decoration:line-through;">(5.0.3</span> 5.0.3)) folder, add -&gt; New Custom Toolbar. We name it &#8220;my svn tools&#8221; and click ok.</p>
<p>Then we rightclick on the newly created toolbar and add -&gt; Custom command, then fill the fields like this:</p>
<div id="attachment_49" class="wp-caption alignnone" style="width: 490px"><img class="size-full wp-image-49" title="screenshot-svn-update-properties" src="http://moisadoru.files.wordpress.com/2009/02/screenshot-svn-update-properties1.png?w=480&#038;h=560" alt="SVN update" width="480" height="560" /><p class="wp-caption-text">SVN update</p></div>
<p>You&#8217;ll notice that I also changed the command&#8217;s icon (I used the arrow_up icon from the <a href="http://www.famfamfam.com/lab/icons/silk/" target="_blank">FamFamFam Silk icon set</a> which are offered for free under a CreativeCommons license). You can do that by clicking &#8220;Change icon&#8221;. You&#8217;ll notice the %d in the &#8220;Start in&#8221; advanced option. That means that the command will be run in the active project&#8217;s folder path. Pay much attention to this specific detail when you have more than one project opened.</p>
<p>Now let&#8217;s add a new command for svn commit:</p>
<div id="attachment_55" class="wp-caption alignnone" style="width: 490px"><img class="size-full wp-image-55" title="screenshot-svn-commit-properties" src="http://moisadoru.files.wordpress.com/2009/02/screenshot-svn-commit-properties1.png?w=480&#038;h=560" alt="SVM commit properties" width="480" height="560" /><p class="wp-caption-text">SVM commit properties</p></div>
<p>You will notice that this time we have something different in the Command field:</p>
<p>svn ci -m &#8220;%(ask:Commit message:)&#8221;</p>
<p>When you commit something, usually you have to write a commit message that describes the nature of the modifications you&#8217;ve made to the code (for example a fix for a specific trac ticket); that&#8217;s what the -m &#8220;message&#8221; does. For this, we are using the %(ask:dialog_title:default_value) construct that tells komodo to popup an input dialog  with the title replaced with the  dialog_title parameter, and the default value replaced with the default_value parameter. The default value is optional. In our case, when we fire that specific command, it will look something like this:</p>
<p><img class="alignnone size-full wp-image-9" title="screenshot-svn-commit" src="http://blog.doru.homeunix.org/wp-content/uploads/2009/02/screenshot-svn-commit.png" alt="screenshot-svn-commit" width="481" height="99" /></p>
<p>After using this a couple of times, you will notice that the field remembers older values that you entered, pretty much like a browser remembers what you tiped in a specific form input.</p>
<p>Now let&#8217;s add the svn cleanup command:</p>
<div id="attachment_51" class="wp-caption alignnone" style="width: 490px"><img class="size-full wp-image-51" title="screenshot-svn-cleanup-properties" src="http://moisadoru.files.wordpress.com/2009/02/screenshot-svn-cleanup-properties1.png?w=480&#038;h=560" alt="SVN cleanup" width="480" height="560" /><p class="wp-caption-text">SVN cleanup</p></div>
<p>That was simple. I used the paitbrush icon.</p>
<p>What we need next is a command that adds newly created files into the versioning system.</p>
<p>I&#8217;ve used a code snippet from <a href="http://codesnippets.joyent.com/posts/show/450" target="_blank">here</a>. It looks like this:<br />
<code>for i in `svn st | grep ? | awk -F "      " '{print $2}'`; do svn add $i; done </code></p>
<div id="attachment_52" class="wp-caption alignnone" style="width: 490px"><img class="size-full wp-image-52" title="screenshot-add-new-files-to-svn-properties" src="http://moisadoru.files.wordpress.com/2009/02/screenshot-add-new-files-to-svn-properties1.png?w=480&#038;h=560" alt="SVN add" width="480" height="560" /><p class="wp-caption-text">SVN add</p></div>
<p>I used the add icon from the FamFamFam icon set.</p>
<p>So far so good. It&#8217;s time to test our work. Go to the View menu -&gt; Toolbars and check &#8220;my svn tools&#8221;. Your Komodo&#8217;s toolbar should look like this:</p>
<div id="attachment_53" class="wp-caption alignnone" style="width: 489px"><img class="size-full wp-image-53" title="toolbar" src="http://moisadoru.files.wordpress.com/2009/02/toolbar1.png?w=479&#038;h=64" alt="Toolbar" width="479" height="64" /><p class="wp-caption-text">Toolbar</p></div>
<p>You will notice that our four commands appeared on the Komodo&#8217;s toolbar.</p>
<p>If you did everything right, you should be able to use those commands on any project that is versioned through subversion.</p>
<p>Very important: remember, in order for those commands to work properly, you must set the project you intend to use the tools as Active Project.</p>
<p>This is no a complete solution by far. I intend to dive more deeply into Komodo and it&#8217;s extensibility features, and hopefully implement a more complete solution that has let&#8217;s say all the important subversion commands.</p>
<p><a title="Simple SVN Komodo Package" href="http://doru.homeunix.org/stuff/simple-svn.kpz">Here is the exported toolbar package</a>. Download and import it into your Komodo, play with it, modify it, make it look the way you like.</p>
<p>Happy coding !</p>
<p>UPDATE:</p>
<p>Here is how to do svn checkout:</p>
<div id="attachment_54" class="wp-caption alignnone" style="width: 476px"><img class="size-full wp-image-54" title="svn-co" src="http://moisadoru.files.wordpress.com/2009/02/svn-co1.png?w=466&#038;h=579" alt="SVN checkout" width="466" height="579" /><p class="wp-caption-text">SVN checkout</p></div>
<p>The command uses the nice little program called <a title="Zenity" href="http://library.gnome.org/users/zenity/" target="_blank">Zenity</a> (which makes dialogs). The command used for checkout is:</p>
<p><code>svn co %(ask:Repository URL:) `echo | zenity --file-selection --directory --title="Checkout SVN"` --username="%(ask:SVN username:anonymous)" --password="%(askpass:SVN password)" | zenity --progress --pulsate --title="SVN Checkout" --text="Please wait for the checkout to complete" --auto-kill --auto-close</code></p>
<p>You can <a title="SVN checkout package" href="http://doru.homeunix.org/stuff/svn-checkout.kpz">download the kpz file from here</a>, and import it into your Komodo. Enjoy !</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moisadoru.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moisadoru.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/moisadoru.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/moisadoru.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moisadoru.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moisadoru.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moisadoru.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moisadoru.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moisadoru.wordpress.com&amp;blog=3432839&amp;post=1&amp;subd=moisadoru&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://moisadoru.wordpress.com/2009/02/12/home-baked-svn-support-for-komodo-edit/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/757d86c17937ce92fc3df001444ae12b?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Doru Moisa</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/02/screenshot-svn-update-properties1.png" medium="image">
			<media:title type="html">screenshot-svn-update-properties</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/02/screenshot-svn-commit-properties1.png" medium="image">
			<media:title type="html">screenshot-svn-commit-properties</media:title>
		</media:content>

		<media:content url="http://blog.doru.homeunix.org/wp-content/uploads/2009/02/screenshot-svn-commit.png" medium="image">
			<media:title type="html">screenshot-svn-commit</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/02/screenshot-svn-cleanup-properties1.png" medium="image">
			<media:title type="html">screenshot-svn-cleanup-properties</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/02/screenshot-add-new-files-to-svn-properties1.png" medium="image">
			<media:title type="html">screenshot-add-new-files-to-svn-properties</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/02/toolbar1.png" medium="image">
			<media:title type="html">toolbar</media:title>
		</media:content>

		<media:content url="http://moisadoru.files.wordpress.com/2009/02/svn-co1.png" medium="image">
			<media:title type="html">svn-co</media:title>
		</media:content>
	</item>
	</channel>
</rss>
