<?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>Max says... &#187; PHP</title>
	<atom:link href="http://maxmanders.co.uk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://maxmanders.co.uk</link>
	<description>thoughts of a web developer</description>
	<lastBuildDate>Tue, 31 Aug 2010 07:25:19 +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>Revert to PHP 5.2 in Ubuntu 10.04 (Lucid Lynx)</title>
		<link>http://maxmanders.co.uk/web-development/revert-to-php-5-2-in-ubuntu-10-04-lucid-lynx/</link>
		<comments>http://maxmanders.co.uk/web-development/revert-to-php-5-2-in-ubuntu-10-04-lucid-lynx/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 17:32:08 +0000</pubDate>
		<dc:creator>maxmanders</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://maxmanders.co.uk/?p=174</guid>
		<description><![CDATA[Despite suppressing updates of my LAMP stack, the upgrade to Ubuntu 10.04 ignored that, and as such I now have PHP 5.3.X installed.  Ordinarilly this woud be fine, but one of the open source web applications I work with doesn&#8217;t play well with PHP 5.3.X.  I needed a simple way to revert to a previous [...]]]></description>
			<content:encoded><![CDATA[<p>Despite suppressing updates of my LAMP stack, the upgrade to Ubuntu 10.04 ignored that, and as such I now have PHP 5.3.X installed.  Ordinarilly this woud be fine, but one of the open source web applications I work with doesn&#8217;t play well with PHP 5.3.X.  I needed a simple way to revert to a previous 5.2.X version of PHP.  The version in the Ubuntu 9.10 (Karmic) repositories would do the trick, so it was jsut a case of forcing Ubuntu to honour the 9.10 versions of various PHP packages over the 10.04 versions.</p>
<p>First, we get a list of all the currently installed PHP packages:</p>
<pre class="brush:bash">sudo dpkg -l | grep php &gt; /tmp/php.packages
</pre>
<p>Next we remove the currently installed PHP packages:</p>
<pre class="brush:bash">sudo apt-get remove --purge $(dpkg -l | grep php)
</pre>
<p>Now we need to create an alternative sources list:</p>
<pre class="brush:bash">sed s/lucid/karmic/g /etc/apt/sources.list |\
sudo tee /etc/apt/sources.list.d/karmic.list
</pre>
<p>Having done that, we need to generate an aptitude preferences file for PHP:</p>
<pre class="brush:bash">awk '{print "Package: " $0; print "Pin: release a=karmic\nPin-Priority: 991\n"}' /tmp/php.packages |\
sudo tee /etc/apt/preferences.d/php
</pre>
<p>This preferences file tells aptitude that for each listed package, we want to pin down the installation candidate to that from the Karmic repositories.  We can now install the packages that we previously removed, but this time the versions from the Karmic repositories:</p>
<pre class="brush:bash">sudo apt-get install $(cat /tmp/php.packages | tr "\n" " ")
</pre>
<p>A quick restart of Apache and everything seems to be working with the older version of PHP!</p>
]]></content:encoded>
			<wfw:commentRss>http://maxmanders.co.uk/web-development/revert-to-php-5-2-in-ubuntu-10-04-lucid-lynx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UK Geocoding &#8211; Update</title>
		<link>http://maxmanders.co.uk/development/uk-geocoding-update/</link>
		<comments>http://maxmanders.co.uk/development/uk-geocoding-update/#comments</comments>
		<pubDate>Sun, 11 Apr 2010 16:22:51 +0000</pubDate>
		<dc:creator>maxmanders</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YQL]]></category>

		<guid isPermaLink="false">http://maxmanders.co.uk/?p=171</guid>
		<description><![CDATA[I&#8217;ve updated the UK Geocoding site to provide better documentation, and a UI for geocoding, in addition to the XML API.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve updated the <a href="http://ukgeocode.maxmanders.co.uk/">UK Geocoding site</a> to provide better documentation, and a UI for geocoding, in addition to the XML API.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxmanders.co.uk/development/uk-geocoding-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UK Geocoding</title>
		<link>http://maxmanders.co.uk/development/uk-geocoding/</link>
		<comments>http://maxmanders.co.uk/development/uk-geocoding/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 12:40:05 +0000</pubDate>
		<dc:creator>maxmanders</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[YQL]]></category>

		<guid isPermaLink="false">http://maxmanders.co.uk/?p=166</guid>
		<description><![CDATA[After a little hard work, I&#8217;m releasing my attempt to address the shortfall in accurate UK geocoding services.  Courtesy of open data provided by Ordnance Survey Open Click-Point, some sed, SQLite, PHP and YQL I&#8217;ve produced a REST API, and a YQL datatable.  I&#8217;ve also written a more thorough account of this by way of [...]]]></description>
			<content:encoded><![CDATA[<p>After a little hard work, I&#8217;m releasing my attempt to address the shortfall in accurate UK geocoding services.  Courtesy of open data provided by Ordnance Survey Open Click-Point, some sed, SQLite, PHP and YQL I&#8217;ve produced a REST API, and a YQL datatable.  I&#8217;ve also written <a title="UK Geocoding" href="http://maxmanders.co.uk/uk-geocode/">a more thorough account</a> of this by way of documenation.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxmanders.co.uk/development/uk-geocoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing With Perl Sockets</title>
		<link>http://maxmanders.co.uk/general/playing-with-perl-sockets/</link>
		<comments>http://maxmanders.co.uk/general/playing-with-perl-sockets/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 17:47:08 +0000</pubDate>
		<dc:creator>maxmanders</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://maxmanders.co.uk/?p=99</guid>
		<description><![CDATA[At work, I have a Snom 360 IP phone that is hooked up to our internal Asterisk PBX.  If I&#8217;m listening to music with my headphones in, I&#8217;m not always aware that my phone is ringing &#8211; some Perl and PHP hacking later, I&#8217;ve got a crude (and work-in-progress) solution. The phone has an internal [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I have a <a href="http://www.snom.com/en/products/snom-360-voip-phone/">Snom 360</a> IP phone that is hooked up to our internal <a href="http://www.asterisk.org/">Asterisk</a> PBX.  If I&#8217;m listening to music with my headphones in, I&#8217;m not always aware that my phone is ringing &#8211; some Perl and PHP hacking later, I&#8217;ve got a crude (and work-in-progress) solution.<span id="more-99"></span></p>
<p>The phone has an internal web server that lets the user customise a number of options.  The one I&#8217;m interested in is &#8216;Action URI&#8217;.  When a call comes through to my phone, I can enter a URI that my phone will request.  I can send arbitrary parameters in the query string, e.g. a message or the phone number of the caller.  My solution involves a PHP script that the phone can request, a simple Perl socket server sitting listening on my laptop, and a simpel Perl Tk script that will open a window to alert me to the call.</p>
<p>The PHP script that my phone requests is quite simple:</p>
<pre class="brush:perl">
// Hostname of machine
$host = 'somehost';
// Port to connect to
$port = '7890';
$timeout = 30;
$message = $_GET['message'];

$socket = fsockopen($host, $port, $errnum, $errstr, $timeout);
if (!is_resource($socket))
{
exit("Cannot connect: " . $errnum . " " . $errstr);
}
else
{
fputs($socket, $message);
}
fclose($socket);
</pre>
<p>This script is called from my phone and connects to the socket server listening on my laptop.  The code for the corresponding socket server follows:</p>
<pre class="brush:perl">
use strict;
use IO::Socket;
use Net::hostent;

my $PORT = 7890;
my $IP = '192.168.0.1';

my $serverSocket = IO::Socket::INET-&gt;new(
    Proto =&gt; 'tcp',
    LocalHost =&gt; $IP,
    LocalPort =&gt; $PORT,
    Listen =&gt; SOMAXCONN,
    Reuse =&gt; 1,
) or die("Cannot create socket: $!\n");

while (my $clientSocket = $serverSocket-&gt;accept())
{
    $clientSocket-&gt;autoflush(1);
    while (&lt;$clientSocket&gt;)
    {
        `/path/to/tk/script/showMessage.pl "$_"`;
    }
    close($clientSocket);
}
</pre>
<p>This Perl script listens in the background for incoming connections and passes any data it receives to a Perl TK script that displays this data in the form of a simple window on display 0:0.  Here&#8217;s the code for th Perl Tk srcript:</p>
<pre class="brush:perl">
use strict;
use Tk;
use Tk::Font;

my $message = $ARGV[0];

my $mainWindow = MainWindow-&gt;new();
$mainWindow-&gt;minsize(qw(500 200));
$mainWindow-&gt;title("Incoming Call");
$mainWindow-&gt;configure(-background =&gt; 'white');

my $font = $mainWindow-&gt;Font(
    -family =&gt; 'Arial',
    -size =&gt; '24',
);

my $acceptButton = $mainWindow-&gt;Button(
    -text =&gt; $message,
    -background =&gt; 'red',
    -command =&gt; \&amp;exit,
    -foreground =&gt; 'white',
    -font =&gt; $font,
);

$acceptButton-&gt;pack(
    -side =&gt; 'bottom',
    -expand =&gt; 1,
    -fill =&gt; 'both'
);

$mainWindow-&gt;withdraw();
$mainWindow-&gt;update();
my $winXPos = int(($mainWindow-&gt;screenwidth - $mainWindow-&gt;width) / 2);
my $winYPos = int(($mainWindow-&gt;screenheight - $mainWindow-&gt;height) / 2);
$mainWindow-&gt;geometry("+$winXPos+$winYPos");
$mainWindow-&gt;deiconify();

MainLoop();
</pre>
<p>There&#8217;s no doubt about it, this combination of scripts is crude, insecure, and really more of a proof of concept.  Nonetheless, it serves my purposes and hopefully can tidy it up as time allows.</p>
]]></content:encoded>
			<wfw:commentRss>http://maxmanders.co.uk/general/playing-with-perl-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
