<?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>theChrisWalker.net &#187; PHP</title>
	<atom:link href="http://thechriswalker.net/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://thechriswalker.net</link>
	<description>I like Web Development</description>
	<lastBuildDate>Tue, 31 Aug 2010 07:42:25 +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>C, Go and other languages</title>
		<link>http://thechriswalker.net/2010-08/c-go-and-other-languages.html</link>
		<comments>http://thechriswalker.net/2010-08/c-go-and-other-languages.html#comments</comments>
		<pubDate>Mon, 16 Aug 2010 21:15:42 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[GoLang]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=221</guid>
		<description><![CDATA[OK, so I&#8217;m a self-taught programmer. I studied maths at Uni and I really enjoyed pure maths. Not &#8220;Applied Maths&#8221;, not &#8220;Computational Maths&#8221;, but Pure Maths. Basically that means a whole lot of abstract stuff with plenty of logic mixed in. Whilst Maths has a lot in common with programming, and understanding abstract concepts and [...]]]></description>
			<content:encoded><![CDATA[<p>OK, so I&#8217;m a self-taught programmer. I studied maths at Uni and I really enjoyed pure maths. Not &#8220;Applied Maths&#8221;, not &#8220;Computational Maths&#8221;, but Pure Maths. Basically that means a whole lot of abstract stuff with plenty of logic mixed in.</p>
<p>Whilst Maths has a lot in common with programming, and understanding abstract concepts and applying logic to them easily is super-helpful when programming, knowing maths doesn&#8217;t mean your know or understand programming. Only when you start to learn programming can you apply the maths you know to it.</p>
<p><span id="more-221"></span></p>
<p>PHP is an easy starting block. It&#8217;s interpreted, so no compiling necessary. It fits with Apache very well and packages like XAMPP make setting up an environment very simple. It&#8217;s easy to code in an iterative style, simply trying new things and seeing how they work, because you can do this in 2 windows on your computer. One has code, the other your web browser.</p>
<p>So I learnt PHP. I was working in technical support for an ISP at the time and basically wrote tools to help me do that job. For instance one of the first things I wrote was a tool that you pasted in email headers, and it worked out what hops were made and the time delay between each one. As time went on I got more fluent with the language and wrote all sorts of things from a socket-level application that tested the average logon time to a mail server, to an AJAX application for choosing who should make the next Tea round (that would have been &#8220;The Next Big Thing&#8221; had I continued with it, and the &#8220;Wheel of Tea&#8221; would be on everyone&#8217;s lips like Facebook is now!).</p>
<p>And so I considered myself a programmer. I shifted most of my computer away from Windows to Linux and became a general geek. Now after 5 years or so of programming in PHP, I have just started to dabble in real programming. C is very different to PHP. I love it and hate it at the same time. OK, I mostly hate it (but I love it when a plan comes together). I was spurred on by the fact that my first ever C program (which wasn&#8217;t just a hello world I&#8217;ll have you know, but a IPv4/6 UDP listener) worked FIRST try. I&#8217;ve never written anything that worked first time before! </p>
<p>This turned out to be a fluke and I have encounter my fair share of error since, but I digress. The point is that C programming opens up a new world of possibility for me. Routers that run OpenWRT &#8211; I can write applications for. Long-standing daemons that seem to fall over in PHP are now trivial to control more finely. OK so it&#8217;s a lot harder to figure out how you need to structure your program and the pardigms are very different but the results are worth it.</p>
<p>Then I found Go. Google&#8217;s Open Source, designed for Multi-Core, Concurrent programming with automatic garbage collection and interpreter-like compile speeds, whilst remaining within 10-20% of the speed of the final program compared with C. That sounds like a win to me &#8212; if Google is to be believed. The langauge is very immature and I have read numerous articles on the web which claim it&#8217;s performance isn&#8217;t everything Google claim and only for massive (1000k+ lines of code with vastly complex dependencies) projects are compile times significantly less than gcc for C. </p>
<p>I can&#8217;t really comment. Most of the things Go claims to be able to do very well I have never needed, and my biggest application in Go so far is hello-world.go, which was &#8212; oh, I don&#8217;t know &#8212; 10 lines of code? that a generous guestimate. However I do see some of its other features to be very useful for the type of program I would write in it. I.e. horizontally scalable.</p>
<p>Horizontal Scalability is so important. Can you application perform under pressure? Of course not. Pressure is relative and every app will reach a limit. Now if you can only scale vertically, then &#8220;tu es fucked&#8221; (pardon my french). You will eventually not be able to go any higher. But if you can scale horizontally, you have no limits. And Go is desinged for concurrency and non-blocking, asynchronous communications. Using practices like that it would be easy to setup clusters of programs, scaling horizontally.</p>
<p>Of course programs like that are still tricky to build, but Go has the tools as part of it&#8217;s grammer to make it easier. C on the other hand is a basterd, but a supremely powerful one. PHP and other interpreted languages hang back, never going to have the performance of the compiled code (although Python can be pretty damn quick at certain tasks!), but being so much more accessible to the new programmer.</p>
<p>OK, so this post didn&#8217;t really go anywhere. Still I hope you found it interesting. I am learning new sides to programming all the time and am excited by new developments. Go may not be perfect (and has a rubbish name for trying to find info on using Google! Try search for &#8220;Go Program&#8221; and see if any of the results are about a program written in Go &#8212; I&#8217;ll wait &#8212; I didn&#8217;t think so&#8230;) but it has potential and show that people are tyring to think differently about how problems can be tackled and that is definitely a good thing!</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-08/c-go-and-other-languages.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5 WebSockets, very cool. (part 1)</title>
		<link>http://thechriswalker.net/2010-05/html5-websockets-very-cool-part-1.html</link>
		<comments>http://thechriswalker.net/2010-05/html5-websockets-very-cool-part-1.html#comments</comments>
		<pubDate>Fri, 28 May 2010 14:45:32 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Not Code]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=215</guid>
		<description><![CDATA[I only found out about these at the Future of Web Design on Tuesday. I knew they existed in the spec but had never really investigated what they were or how they worked. Now I know I am excited. It seems they are to web apps what the XMLHTTPRequest was when it started to get [...]]]></description>
			<content:encoded><![CDATA[<p>I only found out about these at the Future of Web Design on Tuesday. I knew they existed in the spec but had never really investigated what they were or how they worked. Now I know I am excited. It seems they are to web apps what the XMLHTTPRequest was when it started to get used for AJAX. So let&#8217;s look at what they are, and then why they can be so beneficial to web development. It&#8217;s also worth pointing out at this stage that only Chrome 4+ (I think that version, I&#8217;m writing from memory) supports WebSockets natively although apparently Mozilla want to implement them in the next iteration of Firefox (they are already available with an add-on), so don&#8217;t expect to be using them in any non-specialist projects just yet.</p>
<p><span id="more-215"></span></p>
<h2>What are WebSockets?</h2>
<p>WebSockets are a connection that the browser makes to a server. Unlike a normal HTTP request, this is not a simple &#8220;send request&#8221;, &#8220;receive response&#8221; connection. This is a persistent and full-duplex connection. They can run over port 80 (or 443 for a WebSocket over TLS/SSL) and so have little difficulty with firewalls. There are some concerns over their interaction with proxies, particularly transparent ones. Once the browser sets up the WebSocket, you can send UTF8 text over it, and receive text data from the server. All this sending and receiving over data requires no more headers and only a 2 byte overhead per message.</p>
<h2>Why are they going to be so useful?</h2>
<p>It&#8217;s really the last sentence of that last paragraph that is important. The problem is trying to get data from the server when it&#8217;s available. Web apps using AJAX (or similar techniques), have to ask for data and then get a response, i.e. polling for updates or using Comet-like long polling techniques &#8211; where the request is made and the connection opened but the response is delayed until the server decides it has something useful to say. The Comet technique allows much better real-time updates from the server, but there&#8217;s still the overhead of the HTTP request headers and then the response headers/content.</p>
<p>WebSockets aim to alleviate both issues. Once the socket is open, data can flow from the server to the client whenever the server decides it wants to. Also the client can send information to the server without have to send any extra headers, any info it receives from the server is also header free and therefore the process is very efficient. HTTP headers tend to bulk up with Cookies and remain the same size irrespective of the payload sent.</p>
<h2>Do you have an example I can actually use?</h2>
<p>I do, but it&#8217;s not exactly ready for distribution yet. I built a very basic chat client that uses WebSockets as a demo for myself. The hardest bit was writing a socket server in PHP that could handle multiple clients and manage the broadcasting of data to them. I will post all the code in part 2 &#8212; watch this space! (in the mean time a search for &#8220;websocket&#8221; on Google Code will find you some examples (it&#8217;s what I based my code on&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-05/html5-websockets-very-cool-part-1.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VPS Migration for thechriswalker.net &#8211; New Host, New OS, no Plesk</title>
		<link>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html</link>
		<comments>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html#comments</comments>
		<pubDate>Thu, 25 Mar 2010 19:16:21 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Not Code]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Administration]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=198</guid>
		<description><![CDATA[Not that I didn&#8217;t like Plesk. I just have the urge to understand things well, and I couldn&#8217;t understand all of how Plesk worked&#8230; So I wanted it &#8220;all-manual&#8221;, like the true hardcore (read: idiot) I am. I had been using a VPS to host this website (amongst other things) and it was getting old. [...]]]></description>
			<content:encoded><![CDATA[<p>Not that I didn&#8217;t like Plesk. I just have the urge to understand things well, and I couldn&#8217;t understand all of how Plesk worked&#8230; So I wanted it &#8220;all-manual&#8221;, like the true hardcore (read: <em>idiot</em>) I am.</p>
<p>I had been using a VPS to host this website (amongst other things) and it was getting old. It ran on CentOS 4 and used Plesk as a control panel. PHP was down at version 4.2.2 or something and MySQL still at version 4.x. I didn&#8217;t understand server administration as well as I do now and the whole thing was a bit of a mess. So I decided a fresh start, with a VPS on more powerful hardware and built cleanly.</p>
<p>So I went for a basic VPS from <a href="http://www.34sp.com">34SP.com</a> with no control panel and using Ubuntu 9.04 as the OS. They set up the server quickly and so I went about configuring it how I wanted. There were a couple of snags along the road and so I&#8217;ll tell you about them here too.</p>
<p><span id="more-198"></span></p>
<h2>The Basics, disabling root.</h2>
<p>First things first, the VPS came with the root account enabled and that as the only user on the system. Now I like to have my root account disabled and use sudo, so I created an admin user, granted sudo rights and disabled the root account. The command used are below.</p>
<p>Create user and set password:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># useradd admin</span><br />
<span style="color: #666666; font-style: italic;"># passwd admin</span><br />
<span style="color: #666666; font-style: italic;"># visudo</span></div></div>
<p>Now in the sudoer&#8217;s file you&#8217;ll see a line for root which looks something like:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root ALL=(ALL) ALL</div></div>
<p>duplicate this line but with you&#8217;re username:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">admin ALL=(ALL) ALL</div></div>
<p>save and exit. Now log out of <tt>root</tt> and back in as <tt>admin</tt>, then disable the root account:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #660033;">-l</span> root</div></div>
<p>and we&#8217;re done!. Now on this system my home directory wasn&#8217;t created (probably because I didn&#8217;t give the right flags in the <tt>useradd</tt> command. So we need to make it.</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>admin</div></div>
<h2>LAMP Stack</h2>
<p>34SP had installed Apache but not PHP or MySQL, both of which I wanted. In fact I wanted the following:</p>
<ul>
<li> Apache with mod_rewrite</li>
<li> PHP5.3+ (5.3 is important to me) with APC, Xdebug and MongoDB</li>
<li> MongoDB server </li>
<li> MySQL5 server </li>
</ul>
<p>I also needed to migrate my blog from it&#8217;s current location, to the new server. The Blog uses WordPress 2.8.something and the latest version at time of writing is 2.9.2 (time to upgrade!). WordPress doesn&#8217;t mention PHP5.3 support so this could be fun.</p>
<p>So, first hurdle, the default Ubuntu Repositories do not have packages for PHP5.3. This leaves 2 options, compile from source or find a repositiory which does have the packages. Knowing which I&#8217;d prefer and having already heard of dotdeb.org I added the dotdeb.org PHP5.3 repository to my <tt>sources.list</tt> and then I could install PHP5.3.2 and xdebug and apc right from <tt>apt</tt>!</p>
<p>After editing <tt>/etc/apt/sources.list</tt>:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5 php5-mysql php5-cli php5-xdebug php5-apc mysql5-server</div></div>
<p>But I also wanted MongoDB which is only available as a PECL module. So I need the <tt>php5-dev</tt> package. unfortunately, this gave me an error about <tt>libtool</tt> not being the correct version. and the only way to resolve it (that I could find) was to use libtool from the previous Ubuntu release.</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> purge libtool<br />
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>cn.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>hardy<span style="color: #000000; font-weight: bold;">/</span>libtool.deb<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> libtool.deb<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-dev</div></div>
<p>Then it worked like a dream and I could finally use <tt>pecl</tt></p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> pecl <span style="color: #c20cb9; font-weight: bold;">install</span> mongo</div></div>
<p>That was the PHP module, but what about the actual MongoDB server itself? Well, there&#8217;s a repository for that as well. Add it to your sources.list, update then you can <tt>apt-get install mongodb</tt>. no configuration necessary. The phpinfo() output shows the mongo extension installed correctly and the mongo shell functions to show the mongodb server is working fine.</p>
<p>OK, now time to get my blog up and running, so I create a new virtual host in <tt>/etc/apache2/sites-available</tt> and use the apache tool to enable it <tt>sudo a2ensite thechriswalker.net</tt>. I have all my virtual hosts in <tt>/var/www/vhost/<domain>/{httpdocs,logs}</tt>, I change to the httpdocs directory and grab wordpress <tt> wget http://wordpress.org/latest.tar.gz</tt>, unzip and browse to it to see if it worked!</p>
<p>Well, of course it didn&#8217;t &#8211; I hadn&#8217;t done a couple of things. First I needed to restart Apache to enable the Virtual Host I had created. Then I realised that the DNS hadn&#8217;t propagated so I needed to set a static <tt>hosts</tt> entry on my local computer. This done I tried again &#8211; success!</p>
<p>So I dumped the database from the old VPS, copied (scp&#8217;d) my custom theme, plugins and some other non-wordpress content across to the new one. On the new one, I imported the wordpress database and tried to access it again. It took me through a 2 step &#8220;we need to update your database&#8221; (it was 2.8 not 2.9 remember) screen which worked great! That was easier than expected and I haven&#8217;t seen anything behave oddly under PHP5.3 &#8211; result.</p>
<h2>More</h2>
<p>Now I just need to setup the email side of things, I want to be able to send and recieve mail securely through this server, but thats a job for another day&#8230; Also I moved the email for this domain over to Google Apps, as I like GMail so much, so I may not even bother with the email part of this!</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xbox Live Gamercard API</title>
		<link>http://thechriswalker.net/2009-12/xbox-live-gamercard-api.html</link>
		<comments>http://thechriswalker.net/2009-12/xbox-live-gamercard-api.html#comments</comments>
		<pubDate>Thu, 31 Dec 2009 11:34:25 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[xbox]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=155</guid>
		<description><![CDATA[So, got decided to join most of my friends and I got an Xbox 360. Me being me though, I got interested in the way that all the information about your &#8220;Gamertag&#8221; is stored an accessible on the xbox.com website. Wouldn&#8217;t it be fun to do something with this data! As it turns out, I [...]]]></description>
			<content:encoded><![CDATA[<p>So, got decided to join most of my friends and I got an Xbox 360. Me being me though, I got interested in the way that all the information about your &#8220;Gamertag&#8221; is stored an accessible on the xbox.com website. Wouldn&#8217;t it be fun to do something with this data!</p>
<p>As it turns out, I was beaten to the post by Duncan MacKensie (<a href="http://duncanmackenzie.net/Blog/put-up-a-rest-api-for-xbox-gamertag-data">http://duncanmackenzie.net/Blog/put-up-a-rest-api-for-xbox-gamertag-data</a>) who hosts a webservice to retrieve gamer data from Microsoft. <del datetime="2009-12-31T11:41:44+00:00"> I could find <strong>no</strong> details about how this service works, where the data comes from or anything! Either he has a relationship with Microsoft, or he scrapes xbox.com but either way, the data seems pretty consistent and reliable.</del> <em>Actually it turns out this information was right there on his website&#8230; <a href="http://www.duncanmackenzie.net/Blog/if-you-are-wondering-where-i-get-my-xbox-live-info">http://www.duncanmackenzie.net/Blog/if-you-are-wondering-where-i-get-my-xbox-live-info</a> So he gets it as part of his membership to the Xbox Community Developer Program.</em></p>
<p>However, the webservice is great, and returns XML which is fine, but I thought it would be more useful to me to have a PHP API for this data. So I wrote one which retrieves data from Duncans webservice.</p>
<p> <span id="more-155"></span></p>
<p>Then I thought wouldn&#8217;t it be great to be able to use this dynamically in a webpage, so I wrote a service frontend which will return JSON formatted data. Then I thought wouldn&#8217;t it be useful to let other people use this as well, so I modified it and it can now cope with JSONP requests with a &#8220;_callback&#8221; parameter.</p>
<p>OK, so what does this all mean.</p>
<p><strong>The PHP</strong></p>
<p>The class is called gamertag and the usage is very simple:</p>
<div class="codecolorer-container php mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// include the class file</span><br />
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">&quot;gamertag.php&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//instantiate</span><br />
<span style="color: #000088;">$G</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Gamertag<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thechriswalker'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">//get data</span><br />
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$G</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$G</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>which outputs something like this:</p>
<pre class='code'>Array
(
    [Gamertag] => thechriswalker
    [AccountStatus] => Silver
    [State] => Valid
    [ProfileUrl] => http://live.xbox.com/member/thechriswalker
    [TileUrl] => http://avatar.xboxlive.com/avatar/thechriswalker/avatarpic-l.png
    [AvatarFullUrl] => http://avatar.xboxlive.com/avatar/thechriswalker/avatar-body.png
    [Country] => United Kingdom
    [Location] => Bradninch
    [Bio] =>
    [Reputation] => 58.72229
    [ReputationImageUrl] => http://live.xbox.com/xweb/lib/images/gc_repstars_external_12.gif
    [Zone] => Recreation
    [GamerScore] => 230
    [PresenceInfo] => Array
        (
            [Valid] => true
            [Info] => Last seen 12/29/09   playing Modern Warfare® 2
            [Info2] =>
            [LastSeen] => Tue, 29 Dec 2009 21:35:22 +0000
            [Online] => false
            [StatusText] => Offline
            [Title] => Modern Warfare® 2
        )

    [RecentGames] => Array
        (
            [0] => Array
                (
                    [Name] => Modern Warfare® 2
                    [TotalAchievements] => 50
                    [TotalGamerScore] => 1000
                    [Image32Url] => http://tiles.xbox.com/tiles/Z+/tF/12dsb2JgbA9ECgQJGgYfVl5UL2ljb24vMC84MDAwIAABAAAAAPhq63g=.jpg
                    [Image64Url] => http://tiles.xbox.com/tiles/CE/Vx/0Gdsb2JhbC9ECgQJGgYfVl5UL2ljb24vMC84MDAwAAAAAAAAAP9eRRc=.jpg
                    [LastPlayed] => Tue, 29 Dec 2009 21:32:52 +0000
                    [Achievements] => 9
                    [GamerScore] => 115
                    [DetailsURL] => http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%60m%2fl%3b%7cw&amp;compareTo=thechriswalker
                )

            [1] => Array
                (
                    [Name] => PGR 4
                    [TotalAchievements] => 60
                    [TotalGamerScore] => 1250
                    [Image32Url] => http://tiles.xbox.com/tiles/Y1/qn/0Gdsb2JgbA9ECgR8GgMfWSlaL2ljb24vMC84MDAwIAABAAAAAP+IWnw=.jpg
                    [Image64Url] => http://tiles.xbox.com/tiles/DP/ST/12dsb2JhbC9ECgR8GgMfWSlaL2ljb24vMC84MDAwAAAAAAAAAPi89BM=.jpg
                    [LastPlayed] => Mon, 28 Dec 2009 16:59:25 +0000
                    [Achievements] => 5
                    [GamerScore] => 115
                    [DetailsURL] => http://live.xbox.com/en-US/profile/Achievements/ViewAchievementDetails.aspx?tid=%09%5d%3a%15%18*iAq%0b&amp;compareTo=thechriswalker
                )

        )

)</pre>
<p>So now we can easily get at the data. The source code for the class (which is not fully tested, but the basics work!) is at <a href="http://thechriswalker.net/xbox360/gamertag.source.php">http://thechriswalker.net/xbox360/gamertag.source.php</a> (NB it requires either PHP5 (for json_encode) or the PEAR Services_JSON class if you want to use the &#8220;getJSON()&#8221; method).</p>
<p><strong>The JSON</strong></p>
<p>PHP is well and good but what if I want to use a JSON/JSONP (JSONP is for cross-domain information requesting and is very useful for public information services, see http://en.wikipedia.org/wiki/JSON#JSONP) request, well, that can be done at <a href="http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG">http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG</a> for the straight JSON or <a href="http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG&#038;_callback=YOUR_CALLBACK_FUNCTION_NAME"> http://thechriswalker.net/xbox360/?gamertag=YOUR_GAMERTAG&#038;_callback=YOUR_CALLBACK_FUNCTION_NAME</a> for JSONP.</p>
<p>The first returns just JSON with a content type &#8220;application/json&#8221; and the second returns a javascript function call to your callback function with the JSON object as the only parameter and a content type of &#8220;text/javascript&#8221;.</p>
<p>These enabled me to build a simple Google Gadget to display a Gamercard:</p>
<p><center><br />
<script src="http://www.gmodules.com/ig/ifr?url=http://thechriswalker.net/xbox360/xblgamercard.xml&amp;up_gamertag=thechriswalker&amp;synd=open&amp;w=600&amp;h=200&amp;title=Xbox+Live+Gamertag+Info+for+%22chriswalker%22&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script></center></p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2009-12/xbox-live-gamercard-api.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>CakePHP Evangelism and T-Cake</title>
		<link>http://thechriswalker.net/2009-01/cakephp-evangelism-and-t-cake.html</link>
		<comments>http://thechriswalker.net/2009-01/cakephp-evangelism-and-t-cake.html#comments</comments>
		<pubDate>Wed, 28 Jan 2009 23:10:21 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[CakePHP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[T-Cake]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=49</guid>
		<description><![CDATA[So I&#8217;ve had this blog for 3 posts now and none of them has a &#8220;cakephp&#8221; tag yet. Shocking. So here we go&#8230; If you don&#8217;t know what CakePHP is and you&#8217;ve ever created a web application, or even a website that did more than show a static page, then you should check it out. [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve had this blog for 3 posts now and none of them has a &#8220;cakephp&#8221; tag yet. Shocking. So here we go&#8230;</p>
<p>If you don&#8217;t know what <a href='http://cakephp.org' title='Visit the CakePHP website'>CakePHP</a> is and you&#8217;ve ever created a web application, or even a website that did more than show a static page, then you should check it out. CakePHP is a web application framework designed for rapid application development using the <a href='http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller#As_an_architectural_pattern' title='Wikipedia on MVC'>MVC Design Pattern</a> and with a focus on <a href='http://en.wikipedia.org/wiki/Convention_over_configuration' title='Wikipedia on Convetion over Configuration'>Convention over Configuration</a>.</p>
<p>What this means in practical terms is that you can built an access controlled, database driven, dynamic web sites/applications in a fraction of the time that it would to start from scratch. A simple blog could be built in a matter of minutes. I could go on for hours. So I won&#8217;t, but really &#8211; if you make web apps, consider using a framework and CakePHP is excellent.</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2009-01/cakephp-evangelism-and-t-cake.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
