<?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>Rob Allen&#039;s DevNotes &#187; PHP</title>
	<atom:link href="http://akrabat.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://akrabat.com</link>
	<description>Developing PHP software in the Real World, by Rob Allen</description>
	<lastBuildDate>Wed, 01 Sep 2010 14:33:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MongoDB on OS X with the stock PHP installation</title>
		<link>http://akrabat.com/php/mongodb-on-os-x-with-the-stock-php-installation/</link>
		<comments>http://akrabat.com/php/mongodb-on-os-x-with-the-stock-php-installation/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 12:47:54 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1038</guid>
		<description><![CDATA[MongoDB was mentioned a few times at tek and I said that I wanted to have a look at. Travis' article, MongoDB: A first look, came out a few days ago and piqued my interest further. Then Matthew sent me some source code that requires it. The stage was set for getting MongoDB working on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/">MongoDB</a> was mentioned a few times at <a href="http://tek.phparch.com/">tek</a> and I said that I wanted to have a look at.</p>
<p>Travis' article, <a href="http://www.travisswicegood.com/index.php/2010/05/31/mongodb-a-first-look">MongoDB: A first look</a>, came out a few days ago and piqued my interest further. Then <a href="http://weierophinney.net/matthew/">Matthew</a> sent me some source code that requires it. The stage was set for getting MongoDB working on my Mac.</p>
<h3>MongoDB</h3>
<p>I use <a href="http://github.com/mxcl/homebrew">homebrew</a> as a package manager for installing open source bits and bobs like couchdb, git, and hg. Installing MongoDB was simply a case of:</p>
<pre>brew install mongodb</pre>
<p>Once, installed there's a convenient LaunchAgent plist supplied so that mongodb starts with the computer:</p>
<pre>cp /usr/local/Cellar/mongodb/1.4.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist</pre>
<p>And at this point, MongoDB is installed on your Mac and Travis' article and the <a href="http://www.mongodb.org/display/DOCS/Tutorial">tutorial</a> work!</p>
<h3>The Mongo PHP extension</h3>
<p>If you've been following along here for a while, then you'll know that I use the <a href="/phposx">stock PHP that comes with Mac OS X</a>. I've been very happy with it so far and installed <a href="http://xdebug.org/">Xdebug</a> was easy enough using pecl, so I was hopeful that the mongo extension would be equally simple.</p>
<p>Turns out that it is!</p>
<pre>pecl install mongo</pre>
<p>Compiles the extension with no problems.</p>
<p>To add it to your PHP install, edit php.ini and add:</p>
<pre>extension=mongo.so</pre>
<p>A quick <tt>sudo apachectl restart</tt> and phpinfo() shows this:</p>
<p><img src="http://akrabat.com/wp-content/uploads/2010-06-mongodb_phpinfo.png" alt="MongoDB in phpinfo" border="0" width="450" height="218" /></p>
<p>All done! You can now get at MongoDB from your PHP scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/mongodb-on-os-x-with-the-stock-php-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending a file to IE using SSL</title>
		<link>http://akrabat.com/php/sending-a-file-to-ie-using-ssl/</link>
		<comments>http://akrabat.com/php/sending-a-file-to-ie-using-ssl/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 14:29:52 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=960</guid>
		<description><![CDATA[I keep coming across this one, so I'm noting it here so I can find it again. Internet Explorer doesn't like certain headers related to caching when you send it a file from an SSL site. The Microsoft knowledge base article, Internet Explorer is unable to open Office documents from an SSL Web site explains [...]]]></description>
			<content:encoded><![CDATA[<p>I keep coming across this one, so I'm noting it here so I can find it again.</p>
<p>Internet Explorer doesn't like certain headers related to caching when you send it a file from an SSL site. The Microsoft knowledge base article,<a href="http://support.microsoft.com/kb/316431"> Internet Explorer is unable to open Office documents from an SSL Web site</a> explains the problem quite well:</p>
<blockquote><p>When you attempt to open or download a Microsoft Office document (.doc file, .xls file, .ppt file, and so on) from a secure Web site in Internet Explorer, you may receive one of the following error messages, even though the document is available and downloaded from the server</p></blockquote>
<p>It turns out that the problem is directly due to sending these headers:</p>
<pre class="phpcode"><span style="color: #0000BB">
Pragma</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">no</span><span style="color: #007700">-</span><span style="color: #0000BB">cache&nbsp;&nbsp;
Cache</span><span style="color: #007700">-</span><span style="color: #0000BB">control</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">no</span><span style="color: #007700">-</span><span style="color: #0000BB">cache</span><span style="color: #007700">,</span><span style="color: #0000BB">max</span><span style="color: #007700">-</span><span style="color: #0000BB">age</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">,</span><span style="color: #0000BB">must</span><span style="color: #007700">-</span><span style="color: #0000BB">revalidate
</span>
</span></code></pre>
<p>So, make sure you don't!</p>
<p>Incidentally, IE6 also gets upset if you set <tt>max-age</tt> to <tt>0</tt> and attachment to <tt>inline</tt>, so don't do that either!</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/sending-a-file-to-ie-using-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirecting email whilst developing</title>
		<link>http://akrabat.com/php/redirecting-email-whilst-developing/</link>
		<comments>http://akrabat.com/php/redirecting-email-whilst-developing/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 07:25:02 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=906</guid>
		<description><![CDATA[One common problem whilst developing is that you don't want to send emails out to the client (or their clients!). Ideally, we want to alter our development environment so that this doesn't happen, but still allows us to test the contents of emails that are sent by our web applications. Windows On Windows, the mail() [...]]]></description>
			<content:encoded><![CDATA[<p>One common problem whilst developing is that you don't want to send emails out to the client (or their clients!). Ideally, we want to alter our development environment so that this doesn't happen, but still allows us to test the contents of emails that are sent by our web applications.</p>
<h3>Windows</h3>
<p>On Windows, the <tt>mail()</tt> function uses SMTP over port 25. Unless you've changed your php.ini file, then it will try to connect to localhost in order to send an email. On Windows VM, I use <a href="http://www.lastcraft.com/fakemail.php">Fakemail</a>. This is an SMTP mail server written in perl (or python) that store emails as files into a given directory. When your web application sends an email, you check in the directory and look at the files created.  One top tip: alter the script to give each file a <tt>.txt</tt> extension. Then you can double click :)</p>
<p>Fakemail is also very useful in Linux/Mac if you are using the SMTP transport mail in Zend_Mail or Swiftmailer or whatever.</p>
<h3>Linux / OS X</h3>
<p>On the *nix based systems, <tt>mail()</tt> sends email using an application on the system called <em>sendmail</em> (or any number of compatible alternatives). By default it will call the <tt>sendmail</tt> binary, however you can change this in your php.ini with the <tt>sendmail_path</tt> setting. </p>
<p>I set my development boxes like this:</p>
<pre class="phpcode"><span style="color: #0000BB">
sendmail_path&nbsp;</span><span style="color: #007700">=&nbsp;/</span><span style="color: #0000BB">usr</span><span style="color: #007700">/</span><span style="color: #0000BB">local</span><span style="color: #007700">/</span><span style="color: #0000BB">bin</span><span style="color: #007700">/</span><span style="color: #0000BB">trapmail
</span>
</span></code></pre>
<p>Now, mail() will call my <tt>trapmail</tt> script. This script is trivial:</p>
<pre class="phpcode"><span style="color: #0000BB">
formail&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">R&nbsp;cc&nbsp;X</span><span style="color: #007700">-</span><span style="color: #0000BB">original</span><span style="color: #007700">-</span><span style="color: #0000BB">cc&nbsp;
&nbsp;&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">R&nbsp;to&nbsp;X</span><span style="color: #007700">-</span><span style="color: #0000BB">original</span><span style="color: #007700">-</span><span style="color: #0000BB">to&nbsp;
&nbsp;&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">R&nbsp;bcc&nbsp;X</span><span style="color: #007700">-</span><span style="color: #0000BB">original</span><span style="color: #007700">-</span><span style="color: #0000BB">bcc&nbsp;
&nbsp;&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">f&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">A</span><span style="color: #DD0000">"To:&nbsp;rob@akrabat.com"&nbsp;
</span><span style="color: #007700">|&nbsp;/</span><span style="color: #0000BB">usr</span><span style="color: #007700">/</span><span style="color: #0000BB">sbin</span><span style="color: #007700">/</span><span style="color: #0000BB">sendmail&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">t&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">i
</span>
</span></code></pre>
<p>This script causes all emails to be redirect to my email address with the original to, cc and bcc fields renamed in the headers, so they can be checked!. I like this solution even better than Fakemail as it's easier to see exactly what the mail looks like in a mail client, especially for HTML format.</p>
<p>I just wish I had thought of this script myself! However <a href="http://seancoates.com/mail-replacement----a-better-hack">Sean Coates</a> came up with the idea in 2005 and I've been using it every since. </p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/redirecting-email-whilst-developing/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP Advent 2009: On deployment</title>
		<link>http://akrabat.com/php/php-advent-2009-on-deployment/</link>
		<comments>http://akrabat.com/php/php-advent-2009-on-deployment/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 08:33:11 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=843</guid>
		<description><![CDATA[This year I was asked to write an article for PHP Advent 2009 an it's now been published! Automate your Deployment is a look at how to automate the process of deploying your application to the web server. At my company we started automating our deployment systems just over a year and the number of [...]]]></description>
			<content:encoded><![CDATA[<p>This year I was asked to write an article for PHP Advent 2009 an it's now been published!</p>
<p><a href="http://phpadvent.org/2009/automate-your-deployment-by-rob-allen">Automate your Deployment</a> is a look at how to automate the process of deploying your application to the web server. At my company we started automating our deployment systems just over a year and the number of issues we have around deployment of new code to a website has dropped considerably and is no longer a stressful event. </p>
<p>If you aren't currently using an automated deployment script, I can't recommend highly enough that you set yourself a New Year's resolution to investigate the options and implement a system for yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/php-advent-2009-on-deployment/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PHPNW 09 Conference</title>
		<link>http://akrabat.com/php/phpnw-09-conference/</link>
		<comments>http://akrabat.com/php/phpnw-09-conference/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 11:36:55 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[phpnw]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=792</guid>
		<description><![CDATA[The PHPNW 09 Conference took place last Saturday and I've finally found time to write up my thoughts on it. I went up on Friday in order to meet up with the speakers for dinner and also to go to the pre-conference social at the Lass O'Gowrie. The conference was kicked off with an excellent [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://conference.phpnw.org.uk/phpnw09/">PHPNW 09 Conference</a> took place last Saturday and I've finally found time to write up my thoughts on it.</p>
<p>I went up on Friday in order to meet up with the speakers for dinner and also to go to the pre-conference social at the <a href="http://www.thelass.co.uk/">Lass O'Gowrie</a>.</p>
<p><a href="http://www.flickr.com/photos/86569608@N00/4009148157" title="View 'The PHPNW09 speakers' dinner' on Flickr.com"><img src="http://farm3.static.flickr.com/2663/4009148157_e373ff5c4d.jpg" alt="The PHPNW09 speakers' dinner" border="0" width="500" height="334" /></a></p>
<p>The conference was kicked off with an excellent keynote by Kevlin Henney on uncertainty. The main point I took away was that the attitude of "any decision is better than no decision" is completely wrong for software development. It is much better to delay a decision until you have enough information to make it.</p>
<p>There were two tracks for the rest of the day. I listened to <a href="http://lornajane.net/">Lorna Mitchell</a> talk about development best practices in the context of <a href="http://www.joelonsoftware.com/articles/fog0000000043.html">The Joel Test</a>. This was interesting and I was pleased to note that whilst my company doesn't have a score of 12, we have talked about all the items internally.</p>
<p>I then listened to Rowan Merewood of <a href="http://www.plus.net/">Plusnet</a> who talked about introducing new tools and development practices into a team environment. One key point he made was that it is important to have a "champion" on the team to push for the new tool/practice and I couldn't agree more. Everything that has "stuck" in our team has been because someone in the team really cares about it.</p>
<p>The provided lunch was very good and a noticeable step-up from last year's sandwiches :) I also noticed that the WiFi seemed to work well too.</p>
<p><a href="http://www.flickr.com/photos/86569608@N00/4013685710" title="View 'Dinner was excellent' on Flickr.com"><img src="http://farm3.static.flickr.com/2454/4013685710_1e6245016d.jpg" alt="Dinner was excellent" border="0" width="500" height="357" /></a></p>
<p>After lunch, it was my turn to talk about project management. Whilst not something that most of the delegates would do in their day to day work, I hope that they learnt a little of how the project management process works. Maybe, even picking up a few ideas on how they can help out with ensuring a project is a success. I can say with certainty that the most successful projects that I've managed have most closely followed what I talked about. The ones that go wrong are the ones where we take shortcuts which then come back and bite us!</p>
<p>After my talk, <a href="http://derickrethans.nl/">Derick Rethans</a> talked about how useful <a href="http://xdebug.org/">Xdebug</a> is and how to use its many features.</p>
<p>I bowed out of the talks at this point and spent the next couple of hours talking to people and learning interesting stuff on a more personal level.</p>
<p>The closing session included a segment by Microsoft where they talked about <a href="http://www.microsoft.com/expression/">Expression</a>. I found this quite frustrating as I couldn't help but think that they could have used the time better to tell us about how great PHP is on Windows now. They should be shouting about the fact that Windows is now a first class server platform for PHP applications at every opportunity. Not telling us about a wire-framing tool. What do I know though?!</p>
<p>After the conference, <a href="http://www.sun.com/">Sun Microsystems</a> sponsored an open bar which was very much appreciated.</p>
<p><a href="http://www.flickr.com/photos/86569608@N00/4012945839" title="View 'Free drinks after the conference' on Flickr.com"><img src="http://farm3.static.flickr.com/2483/4012945839_801a59031d.jpg" alt="Free drinks after the conference" border="0" width="500" height="334" /></a></p>
<p>On Sunday, a set of informal sessions took place at <a href="http://www.mosi.org.uk/">MOSI</a>. I overslept and managed to miss the first couple of hours and then spent the rest of the time talking to people rather than listening to sessions. It's a habit I have! I also looked around the museum and could quite easily go back and spend a day or two there.</p>
<p><a href="http://www.flickr.com/photos/86569608@N00/4018416153" title="View 'PHPNW09: The day after at MOSI' on Flickr.com"><img src="http://farm3.static.flickr.com/2801/4018416153_9e0d50a305.jpg" alt="PHPNW09: The day after at MOSI" border="0" width="500" height="357" /></a></p>
<p>All in all, PHPNW 09 was a fantastic conference.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/phpnw-09-conference/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Setting up PHP &amp; MySQL on OS X 10.6 Snow Leopard</title>
		<link>http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-6-snow-leopard/</link>
		<comments>http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-6-snow-leopard/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 12:30:37 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=784</guid>
		<description><![CDATA[(Updated 1st May 2010) With OS X 10.6, Apple ships PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. Also, everything is now 64bit. This means that the entire effort required to get a working PHP dev environment for my work is now much easier. /usr/local Ensure that the following directories exist: sudo [...]]]></description>
			<content:encoded><![CDATA[<p><em>(Updated 1st May 2010)</em></p>
<p>With OS X 10.6, Apple ships PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. Also, everything is now 64bit. This means that the entire effort required to get a working PHP dev environment for my work is now much easier. </p>
<h3>/usr/local</h3>
<p>Ensure that the following directories exist:</p>
<pre>
sudo mkdir /usr/local/include
sudo mkdir /usr/local/bin
sudo mkdir /usr/local/lib
sudo mkdir -p /usr/local/man/man1
</pre>
<h3>MySQL</h3>
<ol>
<li>Download the 64bit DMG version of MySQL 5.0.x for OS X 10.6 from <a href="http://dev.mysql.com/downloads/mysql/">mysql.com</a> and install the pkg, the startup item and the pref pane.</li>
<li>Add <tt>/usr/local/mysql/bin</tt> to the path: <tt>vim ~/.bash_profile</tt> and add:
<pre>
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH
export EDITOR=vim
</pre>
<p> at top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)
</li>
<li>Set up MySQL root password:
<pre>
mysqladmin -u root password {new-password}
mysqladmin -u root -p{new-password} -h localhost password {new-password}
mysqladmin -u root -p reload
</pre>
<p>Clear the history file by typing <tt>history -c</tt> so that {new-password} isn't in plain text on the disk.
</li>
</ol>
<h3>Apache</h3>
<ol>
<li><tt>cd /etc/apache2</tt></li>
<li><tt>sudo vim httpd.conf</tt></li>
<li>Find <tt>#LoadModule php5_module        libexec/apache2/libphp5.so</tt> and remove the leading <tt>#</tt></li>
<li>Find <tt>AllowOverride None</tt> within the <tt>&lt;Directory "/Library/WebServer/Documents"&gt;</tt>section and change to<tt>AllowOverride All</tt> so that .htaccess files will work.</li>
<li>Restart Apache: <tt>sudo apachectl restart</tt></li>
<li>Open Finder and navigate to <tt>/Library/WebServer/Documents/</tt></li>
<li>Create a new folder called "orig" and place all files currently in the Documents folder into it.</li>
<li>Create a new file called info.php with <tt>&lt;?php phpinfo();</tt> inside it.
</li>
<li>Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.3.0 at the time of writing).</li>
</ol>
<h3>php.ini</h3>
<ol>
<li><tt>cd /etc</tt></li>
<li><tt>sudo cp php.ini.default php.ini</tt></li>
<li><tt>sudo chmod ug+w php.ini</tt></li>
<li><tt>sudo chgrp admin php.ini</tt></li>
<li><tt>vim php.ini</tt> (assuming your user is a member of the admin group) and change settings appropriately. Change:
<pre>
error_reporting  =  E_ALL | E_STRICT
display_errors = On
html_errors = On
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"
</pre>
<p>(I like to see my xdebug errors in bright orange!)<br />
Also, change all instances of <tt>/var/mysql/mysql.sock</tt> to <tt>/tmp/mysql.sock</tt>
</li>
</ol>
<h3>Xdebug</h3>
<p>Can't have a PHP development environment without <a href="http://www.xdebug.org/">xdebug</a>!</p>
<ol>
<li><tt>sudo pecl channel-update pecl.php.net</tt></li>
<li><tt>sudo pear channel-update pear.php.net</tt></li>
<li><tt>sudo pecl install xdebug</tt></li>
<li>Edit /etc/php.ini and add
<pre>zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"</pre>
<p> after the other extension lines.</li>
<li>Restart apache: <tt>sudo apachectl restart</tt> and check in the phpinfo that xdebug is now loaded.</li>
</ol>
<h3>PHPUnit</h3>
<ol>
<li><tt>sudo pear upgrade-all</tt></li>
<li><tt>sudo pear channel-discover pear.phpunit.de</tt></li>
<li><tt>sudo pear install phpunit/PHPUnit</tt></li>
</ol>
<p>It all works on this machine, anyway :)</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-6-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Changing OS X Terminal colours when ssh&#039;ing into a server</title>
		<link>http://akrabat.com/php/osx-terminal-colours/</link>
		<comments>http://akrabat.com/php/osx-terminal-colours/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:40:25 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=779</guid>
		<description><![CDATA[I recently discovered that iTerm has bookmarks so you can set up a bookmark to ssh into a server and change the colours of the window. This makes it easy to remember which terminal window is for which server. Thinking about it, I wondered if you could change the colours of the standard OS X [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered that iTerm has bookmarks so you can set up a bookmark to ssh into a server and change the colours of the window. This makes it easy to remember which terminal window is for which server.</p>
<p>Thinking about it, I wondered if you could change the colours of the standard OS X Terminal via AppleScript. Inpired by Red Sweater's <a href="http://www.red-sweater.com/blog/220/random-color-terminal">Random Color Terminal</a> post, I wrote some code to automatically change the Terminal colour whenever I ssh into a known server.</p>
<p>As I know PHP and PHP is installed on OS X, I used that :)</p>
<p>The key to controlling AppleScript via PHP is the <tt>osascript</tt> command line application. The code I need specifically is:<br />
<!-- more --></p>
<pre class="phpcode"><span style="color: #0000BB">
system</span><span style="color: #007700">(</span><span style="color: #DD0000">"osascript&nbsp;-e&nbsp;'tell&nbsp;application&nbsp;\"Terminal\"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;targetWindow&nbsp;to&nbsp;window&nbsp;1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;background&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;cursor&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;normal&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;bold&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;tell'&nbsp;"</span><span style="color: #007700">);
</span>
</span></code></pre>
<p>where <tt>$bgColour</tt> and <tt>$fgColour</tt> are comma separated strings containing three numbers between 0 and 65535 as AppleScript colours are 16 bit.</p>
<p>We start by getting a command line solution where we can type:<br />
<tt>    termcolour.php white</tt><br />
or<br />
<tt>    termcolour.php 00ff00</tt><br />
or<br />
<tt>    termcolour.php 255 0 0</tt></p>
<p>and have the background colour of the Terminal change to the colour we have asked for. </p>
<h3>TerminalColour class</h3>
<p>Firstly we need a class that can change the colour of the Terminal window for us and also translate colours from 8bit RGB to 16bit RGB. As it is also useful to be able to specify colours by name, eg. "white", we'll add a lookup system too. I store this in /usr/local/bin.</p>
<p>This class is quite long, so this is a snippet:</p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">TerminalColour
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;protected&nbsp;</span><span style="color: #0000BB">$_colour&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'255'</span><span style="color: #007700">,</span><span style="color: #DD0000">'255'</span><span style="color: #007700">,</span><span style="color: #DD0000">'255'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;List&nbsp;of&nbsp;colours
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">protected&nbsp;</span><span style="color: #0000BB">$_colours&nbsp;</span><span style="color: #007700">=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'white'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'ffffff'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'black'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'000000'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;etc
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/**
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;Set&nbsp;the&nbsp;colour&nbsp;of&nbsp;the&nbsp;topmost&nbsp;Terminal&nbsp;window&nbsp;using&nbsp;AppleScript
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;$bgColour&nbsp;may&nbsp;be&nbsp;either&nbsp;an&nbsp;array&nbsp;of&nbsp;red,&nbsp;green,&nbsp;blue&nbsp;(8&nbsp;bit)&nbsp;or&nbsp;a&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;hex&nbsp;string&nbsp;or&nbsp;a&nbsp;string&nbsp;that&nbsp;matches&nbsp;an&nbsp;entry&nbsp;in&nbsp;the&nbsp;_colours&nbsp;lookup&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;list.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;If&nbsp;$fgColour&nbsp;is&nbsp;null,&nbsp;then&nbsp;automatically&nbsp;use&nbsp;either&nbsp;black&nbsp;or
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;white&nbsp;based&nbsp;on&nbsp;brightness&nbsp;of&nbsp;$bgColour.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;array|string&nbsp;$bgColour
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@param&nbsp;array|string&nbsp;$fgColour
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;@return&nbsp;array
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*/
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">setTerminalColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fgColour</span><span style="color: #007700">=</span><span style="color: #0000BB">null</span><span style="color: #007700">)&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!</span><span style="color: #0000BB">is_null</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getColour</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;convert&nbsp;from&nbsp;8&nbsp;bit&nbsp;colour&nbsp;numbers&nbsp;to&nbsp;16&nbsp;bit&nbsp;ones
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertTo16bit</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getFgColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$bgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$fgColour</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">system</span><span style="color: #007700">(</span><span style="color: #DD0000">"osascript&nbsp;-e&nbsp;'tell&nbsp;application&nbsp;\"Terminal\"
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;targetWindow&nbsp;to&nbsp;window&nbsp;1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;background&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$bgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;cursor&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;normal&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set&nbsp;bold&nbsp;text&nbsp;color&nbsp;of&nbsp;targetWindow&nbsp;to&nbsp;{"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$fgColour&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end&nbsp;tell'&nbsp;"</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>As you can see, there's a variety of helper methods that I've not show here. <tt>setColour()</tt> is the where we map from the types of input that the user will provide to an array. Other that that, it's fairly self-explanatory. </p>
<h3>Change colour from the command line</h3>
<p>Now we need a script that uses our class. <tt>termcolours.php</tt>, that I can execute from the command line to change any given Terminal window to a new background colour. </p>
<p><tt>termcolour.php</tt> is stored in /usr/local/bin and has execute permissions set using <tt>chmod a+x termcolour.php</tt> from the command line:</p>
<pre class="phpcode">
#!/usr/bin/php
<span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">include&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'/TerminalColour.php'</span><span style="color: #007700">;

</span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">$argc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$argv</span><span style="color: #007700">);
exit;

function&nbsp;</span><span style="color: #0000BB">process</span><span style="color: #007700">(</span><span style="color: #0000BB">$argc</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$argv</span><span style="color: #007700">)
{
&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&lt;&lt;&lt;EOT
</span><span style="color: #DD0000">TerminalColour:&nbsp;Set&nbsp;the&nbsp;background&nbsp;colour&nbsp;of&nbsp;a&nbsp;Terminal.app&nbsp;window&nbsp;
USAGE:&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;1.&nbsp;termcolour.php&nbsp;{r}&nbsp;{g}&nbsp;{b}&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;({r},&nbsp;{g},&nbsp;{b}&nbsp;are&nbsp;between&nbsp;0&nbsp;and&nbsp;255)
&nbsp;&nbsp;&nbsp;&nbsp;2.&nbsp;termcolour.php&nbsp;{hexvalue}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;({hexvalue}&nbsp;assumed&nbsp;to&nbsp;be&nbsp;from&nbsp;000&nbsp;to&nbsp;fff&nbsp;or&nbsp;00000&nbsp;to&nbsp;ffffff)

</span><span style="color: #007700">EOT;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">TerminalColour</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;called&nbsp;with&nbsp;three&nbsp;arguments&nbsp;-&nbsp;treat&nbsp;as&nbsp;rgb&nbsp;values&nbsp;(0-255)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_shift</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">);&nbsp;</span><span style="color: #FF8000">//&nbsp;remove&nbsp;name&nbsp;of&nbsp;script
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerminalColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;called&nbsp;with&nbsp;one&nbsp;argument&nbsp;-&nbsp;either&nbsp;a&nbsp;lookup&nbsp;or&nbsp;a&nbsp;hex&nbsp;value
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTerminalColour</span><span style="color: #007700">(</span><span style="color: #0000BB">$argv</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>Again, not complicated. we check number of arguments to the script and if there are none, we display a help message. If there are exactly 1 or 3, then we call <tt>TerminalColour::setTerminalColour()</tt> appropriately.</p>
<h3>Hooking into SSH</h3>
<p>Lastly we hook into ssh and change the colour based on the server name.</p>
<p>To do this, I've used a simple shell script and modified termcolours.php to add some additional colour look up entries.</p>
<p><strong>/usr/local/bin/sshcolours.sh:</strong><br />
/usr/local/bin/termcolour.php $@<br />
/usr/bin/ssh $@<br />
/usr/local/bin/termcolour.php white</p>
<p><strong>termcolour.php</strong></p>
<pre class="phpcode"><span style="color: #0000BB">
</span><span style="color: #FF8000">//...
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">TerminalColour</span><span style="color: #007700">();

&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;add&nbsp;colours&nbsp;for&nbsp;servers
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$colourLookup&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLookupColours</span><span style="color: #007700">();
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$serverColours&nbsp;</span><span style="color: #007700">=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'server1'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$colourLookup</span><span style="color: #007700">[</span><span style="color: #DD0000">'darkblue'</span><span style="color: #007700">],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'server2'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$colourLookup</span><span style="color: #007700">[</span><span style="color: #DD0000">'red'</span><span style="color: #007700">],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'server3'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'C4DFC3'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$tc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addToLookupColours</span><span style="color: #007700">(</span><span style="color: #0000BB">$serverColours</span><span style="color: #007700">);

&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$argc&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">4</span><span style="color: #007700">)&nbsp;{
</span><span style="color: #FF8000">//...
</span>
</span></code></pre>
<p>(not a large change!)</p>
<p>finally, we add an alias to ~/.bash_profile:</p>
<pre class="phpcode"><span style="color: #0000BB">
alias&nbsp;s</span><span style="color: #007700">=</span><span style="color: #0000BB">sshcolours</span><span style="color: #007700">.</span><span style="color: #0000BB">sh
</span>
</span></code></pre>
<p>That's it! I can now type:</p>
<pre>
	s server1
</pre>
<p>and Terminal's background colour turns blue and I'm ssh'd into server 1. </p>
<p>Sometimes I just type <tt>termcolour.php darkred</tt> to remind myself that this terminal window is doing something long-running and not to accidentally close it...</p>
<p>This is a <a href="/wp-content/uploads/terminal_colours.zip">zip file</a> of the relevant files.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/osx-terminal-colours/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A new blog from someone new to PHP</title>
		<link>http://akrabat.com/php/a-new-blog-from-someone-new-to-php/</link>
		<comments>http://akrabat.com/php/a-new-blog-from-someone-new-to-php/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 08:08:11 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Around the web]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=771</guid>
		<description><![CDATA[I met Chris when he was temping for a client of mine doing data entry into an e-commerce system we were writing. Recently he contacted me to let me know that he has now started learning PHP and is starting to develop a career in web development with PHP. I was quite impressed that he [...]]]></description>
			<content:encoded><![CDATA[<p>I met Chris when he was temping for a client of mine doing data entry into an e-commerce system we were writing. Recently he contacted me to let me know that he has now started learning PHP and is starting to develop a career in web development with PHP. I was quite impressed that he had even managed to land himself some freelance work and had a client happy enough to pay him! </p>
<p>He asked me for some advice and I provided some information on the sorts of things he need to learn about and some ideas on where to find communities that will help. </p>
<p>I had recently read Cal Evans' <a href="http://blog.calevans.com/2009/08/10/php-and-community/">PHP and Community</a> post, which contains this gem:</p>
<blockquote><p>
Until all 4.6 million PHP developers are active in the community, there is always a seat at the table. If you are a PHP developer - junior level, architect level or just a weekend warrior - I urge you to get involved.</p>
<p>Start a blog and write about what you have learned. Trust me, if you put up something that isn’t accurate, someone will come along and correct you. That’s a win for everyone.
</p></blockquote>
<p>As a result, I also advised him to start a blog so that he can document what he now knows to the benefit of us all and also allow potential employers the opportunity to understand his skills much better than a mere CV can show.</p>
<p>He's taken this advice and <a href="http://jibbles.co.uk/">http://jibbles.co.uk/</a> has been born. It turns out that Chris is a very good writer - much better than I was when I started (and probably better than I am now too)!  If you are interested in watching a new coder develop into a better coder, then it may be worth keeping an eye on his blog. You could also comment periodically when he needs a pointer to something that he's probably never heard of before :)</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/a-new-blog-from-someone-new-to-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some notes on Zend Server CE for Mac OS X</title>
		<link>http://akrabat.com/php/some-notes-on-zend-server-ce-for-mac-os-x/</link>
		<comments>http://akrabat.com/php/some-notes-on-zend-server-ce-for-mac-os-x/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 05:40:34 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=669</guid>
		<description><![CDATA[I've installed Zend Server CE on my Mac to see where it's got to and it's looking quite usable. The installation puts everything into the usr/local/zend directory which is fairly well laid out so that you can find what you are looking for. There's also a a nice admin system at http://localhost:10081 which allows you [...]]]></description>
			<content:encoded><![CDATA[<p>I've installed Zend Server CE on my Mac to see where it's got to and it's looking quite usable. The installation puts everything into the usr/local/zend directory which is fairly well laid out so that you can find what you are looking for. There's also a a nice admin system at http://localhost:10081 which allows you to restart PHP, view phpinfo(), configure extensions and php.ini. There's also a phpMyAdmin to help administer the bundled MySQL server.</p>
<p>For Mac, this is now one of the better one stop shops for easy PHP &#038; MySQL installation.</p>
<p>Obviously, some things need configuration:</p>
<h3>Set up paths</h3>
<p>You need access to the command line zendctl.sh and mysql tools:</p>
<ul>
<li>Edit ~/.bash_profile and add:
<pre>    PATH=$PATH:/usr/local/zend/bin:/usr/local/zend/mysql/bin
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/zend/lib
</pre>
</li>
<li>Close Terminal and restart it so that your change takes effect.</li>
</ul>
<h3>Change to port 80</h3>
<p>The Apache in Zend Server is configured for 10088 to avoid conflicting with Apple's Web Sharing I suppose. The choice of using port 80  would have been nice as an installation option though.</p>
<p>To use port 80 is easy enough:</p>
<ul>
<li>Stop Apache: <tt>sudo zendctl.sh stop-apache</tt></li>
<li>Edit <tt>/usr/local/zend/apache2/conf/httpd.conf</tt> and replace <tt>Listen 10088</tt> with <tt>Listen 80</tt></li>
<li>Edit <tt>/usr/local/zend/apache2/bin/apachectl</tt> and change <tt>STATUSURL="http://localhost:10088/server-status"</tt> to <tt>STATUSURL="http://localhost:80/server-status"</tt></li>
<li>If you are using vhosts, then edit <tt>/usr/local/zend/apaches/conf/httpd.conf</tt> and replace all instances 10088 with 80</li>
<li>Restart Apache:<tt>sudo zendctl.sh start-apache</tt></li>
</ul>
<h3>Installing PHPUnit</h3>
<p>Update PEAR first:</p>
<pre>    sudo pear channel-update pear.php.net
    sudo pear upgrade-all</pre>
<p>Install PHPUnit:</p>
<pre>    sudo pear channel-discover pear.phpunit.de
    sudo pear install phpunit/PHPUnit</pre>
<h3>Installing Xdebug</h3>
<ul>
<li>Install Xcode so you have a compiler!</li>
<li>Stop Apache: <tt>sudo zendctl.sh stop-apache</tt></li>
<li>Go to http://localhost:10081/ and pick the Server Setup tab. Turn off the Zend Debugger and Zend Data Cache and restart PHP</li>
<li><tt>sudo pecl install xdebug</tt></li>
<li>Edit <tt>/usr/local/zend/etc/php.ini</tt> and add <i>above the [zend]</i> section near the bottom:
<pre>
zend_extension="/usr/local/zend/lib/php_extensions/xdebug.so" 

[xdebug]
xdebug.remote_enable=1
xdebug.remote_host="localhost"
xdebug.remote_port=9000
xdebug.show_local_vars=On
xdebug.var_display_max_data=10000
xdebug.var_display_max_depth=20
</pre>
<p>(you should set up your xdebug settings as you require!)
</li>
<li>Restart Apache:<tt>sudo zendctl.sh start-apache</tt></li>
<li>The Server Setup->Extensions section of the admin interface should now show xdebug.
</li>
</ul>
<p>All in all, it's remarkably easy to set up Zend Server using PEAR and PECL is which how it should be. </p>
<p>The only other gotcha I noticed is that my.cnf is in <tt>/usr/local/zend/mysql/data</tt> whereas I would have thought that <tt>/usr/local/zend/etc</tt> would have been more logical.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/some-notes-on-zend-server-ce-for-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>DPC &#039;09</title>
		<link>http://akrabat.com/php/dpc-09/</link>
		<comments>http://akrabat.com/php/dpc-09/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 20:14:38 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=666</guid>
		<description><![CDATA[The Dutch PHP Conference is over and so it's time to write a short wrap-up. Day 1 The conference was opened by a cool animated video and then Cal Evans welcomed us, with a nice short speech. The keynote was given by Andrei Zmievski of Digg. Andrei is a core devloper and gave an interesting [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.phpconference.nl/">Dutch PHP Conference</a> is over and so it's time to write a short wrap-up.</p>
<h3>Day 1</h3>
<p>The conference was opened by a cool <a href="http://www.vimeo.com/5165858">animated video</a> and then <a href="http://blog.calevans.com/">Cal Evans</a> welcomed us, with a nice short speech. The keynote was given by Andrei Zmievski of Digg. Andrei is a core devloper and gave an interesting overview of what we can expect to see next in PHP. </p>
<p><a href="http://www.flickr.com/photos/86569608@N00/3620815450" title="View 'Cal opens DPC 09' on Flickr.com"><img src="http://farm4.static.flickr.com/3345/3620815450_4d3bb424ca.jpg" alt="Cal opens DPC 09" border="0" width="500" height="333" /></a></p>
<p>I then listened to Paul Reinheimer talk about some problems you can encounter in conceptually easy situations. I found the section about handling account login issues very interesting and it's an area that I now intend to improve in my code. Ben Ramsey followed with a talk on the theory of REST architectures which was interesting, though not directly relevant to anything that we're doing at the moment. Making sure that I understand it when we come to make web service APIs is important though.</p>
<p>After lunch Matthew Weier O'Phinney talked about contributing to open source projects. Matthew gave a great talk with useful information in it. As a contributor to Zend Framework already, I mainly used this talk to learn how to evangelise the concept of contributing to other people. </p>
<p>I stepped out of the next session into the hallway track where I caught up with some people and then checked my email. Then Jan Lehnardt was on to talk about CouchDB. CouchDB fascinates me as it's so different from the relational databases I'm used to. I don't see that we'll be using it soon though - the paradigm shift is significant.</p>
<p>The day ended with the speakers dinner followed by drinking :)</p>
<h3>Day 2</h3>
<p>Day 2 dawned bright and far too early and I managed to leave my power adapter at the hotel, so I had to go back for it, missing the opening keynote. I got back to see most of Eli White's talk on scaling. Eli is a good speaker and the talk was well researched. I know that if I ever need to scale a website to 20 database servers and too many web servers, then I'm going to try and head hunt him...</p>
<p>I was intending to see Juliette Reinders Folmer's talk on UTF-8, but Paul suffered from a video adapter failure and so I lent him my laptop and stayed to watch and make sure he didn't break it. Paul gave another interesting talk whilst looking good in his suit.</p>
<p>After lunch, it was my turn to talk. Although I was nervous at the beginning, I think that I got into my stride and the presentation went well with intelligent questions asked by the audience. I think it helped that I advised the people who knew more than I did to leave before we started :) If you were there and haven't yet rated it, then <a href="http://joind.in/talk/view/579">please leave feedback</a>! </p>
<p>The final breakout session that I attended was another by Ben Ramsey about HTTP. There was more here that was directly relevant to work, but I'd have preferred more on the codes side with less emphasis on the methods.</p>
<p>The session was closed with a conversation between Cal Evans, Ivo Jansch, Andrei Zmievski, Lorna Mitchell and Paul Reinheimer. This took the form of an interview by Cal and Ivo with their guests. It worked quite well, but I felt that the questions for Andrei and Paul were not as well structured as the ones for Lorna. There was a slide show running above their heads with Twitter and Flickr photos from the conference playing. This was very funny :)</p>
<p>In the evening, I went for a meal at a Pancake house that was very enjoyable and I got to see a little bit of Central Amsterdam!</p>
<h3>Conclusion</h3>
<p>Overall, The 2009 version of the Dutch PHP Conference was very successful. It's clear that it is being positioned to become a major conference, not just for Europe, but for the world with a significant focus on the advanced developer.</p>
<p>I will certainly be submitting to talk in 2010 - assuming I can think up some advanced topics to talk about!</p>
<p><a href="http://www.flickr.com/photos/86569608@N00/3622599853" title="View 'Cheers!' on Flickr.com"><img src="http://farm4.static.flickr.com/3594/3622599853_c640ded875.jpg" alt="Cheers!" border="0" width="500" height="400" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/dpc-09/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
