<?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>Ben Longden &#187; php</title>
	<atom:link href="http://nocarrier.co.uk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://nocarrier.co.uk</link>
	<description>PHP and some other bits...</description>
	<lastBuildDate>Sat, 28 Jan 2012 12:06:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Magento Enterprise PageCache</title>
		<link>http://nocarrier.co.uk/2012/01/magento-enterprise-pagecache/</link>
		<comments>http://nocarrier.co.uk/2012/01/magento-enterprise-pagecache/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 20:28:13 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[magento]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=103</guid>
		<description><![CDATA[<p>I have split this post into two parts &#8211; starting with how pages are cached in the first place, and then how Magento retrieves a page from the cache before falling back to dispatching a controller.</p> <p>How pages are cached</p> <p>The Magento enterprise page cache module observes several events that are fired during the course [...]]]></description>
			<content:encoded><![CDATA[<p>I have split this post into two parts &#8211; starting with how pages are cached in the first place, and then how Magento retrieves a page from the cache before falling back to dispatching a controller.</p>
<p><strong>How pages are cached</strong></p>
<p>The Magento enterprise page cache module observes several events that are fired during the course of dispatching your controller and sending a full page in the response. I&#8217;m going to dive into only a few of them &#8211; the main observers that actually cause your content to end up in the page cache, and then exactly how Magento gets it back out again.</p>
<p>The first thing we&#8217;re going to look at is how Magento caches pages, and that starts with the observation of the &#8216;controller_action_predispatch&#8217; event &#8211; triggered before a request is dispatched (but after we have determined we will not be fulfilling the request from the cache). It&#8217;s here that the PageCache module will determine if the request that&#8217;s about to be dispatched is to be cached for subsequent requests. There are many things that will prevent a page from being cached and we can start by looking at these.</p>
<p>Examine the processPreDispatch method in Enterprise_PageCache_Model_Observer. This is the event that is fired on the controller_action_predispatch event. All the handlers first check to ensure that the page cache is enabled before doing anything else. Then we examine the no cache cookie and set a flag (memorize_disabled) in the session.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_processor<span style="color: #339933;">-&gt;</span><span style="color: #004000;">canProcessRequest</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_processor<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestProcessor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>The first of the above two condiditions does some basic validation on the request. $this->_processor will normally be an instance of &#8216;Enterprise_PageCache_Model_Processor&#8217; by this point (it&#8217;s instantiated by the &#8216;enterprise_pagecache/processor&#8217; model here so can be overridden), and here we will find the canProcessRequest method. First, we dip into the isAllowed method where we check that we&#8217;ve generated a requestId during the construction of this object. The requestId will become important later on in the process as it provides the key into your cache storage backend for the page content and needs to be reliably recreated based on the request parameters. We then check that the request is not over https, the no cache cookie (NO_CACHE) is not present, the no_cache GET variable is not present and that full page caching is enabled. If any of these checks fail we do not process this request any further in the full page cache module.</p>
<p>Assuming we pass, we move onto checking the configuration. We inspect the page depth parameter (the number of variations a page can have based on the number of variables in the query string). If we&#8217;re over the limit, the page is not cached. Then we check the cache settings for pages that are not in the default currency (system/page_cache/multicurrency = 0 and the presence of the CURRENCY cookie in the request).</p>
<p>The second of the two checks above is where we examine how the page is going to be cached. This is configured in &#8216;frontend/cache/requests&#8217; and the defaults are found in app/code/core/Enterprise/PageCache/etc/config.xml in the following section of XML. By default all cms, catalog/category and catalog/product pages have a processor configured.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;requests<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cms<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>enterprise_pagecache/processor_default<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cms<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catalog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>enterprise_pagecache/processor_category<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/catalog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catalog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>enterprise_pagecache/processor_product<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/product<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/catalog<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/requests<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>getRequestProcessor is where this configuration is examined and we we use the request data to attempt to construct a processor for the target page. Assuming one is configured, Magento is now ready to cache the page for the next request.</p>
<p>If at this point it looks as though we&#8217;re going to cache the page, the independent block cache is disabled and the first peice of setting up the cache is complete.</p>
<p>The next time we&#8217;re back in the PageCache code is once the request has been handled and we&#8217;re about to send the response. This is accomplished by hooking into the controller_front_send_response_before event and executing the &#8216;cacheResponse&#8217; method on the observer. We very quickly end up back in the processor and in the processRequestResponse method.</p>
<p>The first two calls will be familiar. The same methods (canProcessRequest and getRequestProcessor) are called again &#8211; however the processor for this request already exists so the second method returns immediately. We delegate to the configured processor (configured above) at this point and call the &#8216;allowCache&#8217; method with the Request object as a parameter. A number of further checks are done which could prevent the request from being cached &#8211; the presence of &#8216;___store&#8217; or &#8216;___from_store&#8217; in the query string (for the default processor) or the presence of the no cache flag in the session data.</p>
<p>Finally we&#8217;re actually ready to cache the response. Some filtering occurs to strip out blocks and replace them with placeholders (blocks can be cached independently from the page &#8211; to allow for independant cache rules &#8211; like the navigation menu which can persist across multiple pages). The placeholder configuration is stored in app/code/core/Enterprise/PageCache/etc/cache.xml and is structured like the following (this is a real example for the catalog/navigation block).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;placeholders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;catalog_navigation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;block<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>catalog/navigation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/block<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>catalog.topnav<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;placeholder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CATALOG_NAVIGATION<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/placeholder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;container<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Enterprise_PageCache_Model_Container_Catalognavigation<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/container<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache_lifetime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>86400<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache_lifetime<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/catalog_navigation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/placeholders<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The above peice of XML declares the catalog/navigation block to be cached separately to any page that is appears on with CATALOG_NAVIGATION as the placeholder. It specifies the container class (used during storing and extracting the block) and the lifetime in seconds for the cached block.</p>
<p>Blocks are marked up at the time they are rendered and you can view them in the HTML source code between comment blocks that consist of the placeholder value defined in cache.xml, and a hash that is made up by the md5 sum of the results of calling the getCacheKey. They look something like the following (again, using CATALOG_NAVIGATION as an example).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--{CATALOG_NAVIGATION_a61df2dc9b9e5868f17a56461177d8c4}--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>some html<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #808080; font-style: italic;">&lt;!--/{CATALOG_NAVIGATION_a61df2dc9b9e5868f17a56461177d8c4}--&gt;</span></pre></div></div>

<p>This functionality gives you the ability to be able to cache blocks separately to the full page &#8211; with their own rules on how long they stay in the cache for (and independently of the page that they are on). This means that blocks can be made to be cached across pages rather than within them &#8211; meaning that blocks such as catalog/navigation need only be generated once &#8211; and served up from the cache for every request after that regardless of if the page itself is being served from the cache.</p>
<p><strong>How pages are served up from the cache</strong></p>
<p>Rather unlike how pages end up in the cache (using observers to watch for specific points in the dispatch process for a request), the method by which Magento retrieves information from the cache is somewhat more hard coded. Before dispatching the front controller in Mage_Core_Model_App::run (one of the very first methods that gets called in fulfilling a request) a check is done to see if the current request can be served up from the pages in the cache. This happens inside Mage_Core_Model_Cache::processRequest where we immediately check to see if there is a request processor configured that we can check the request against. The request processors are configured inside app/etc/enterprise.xml &#8211; the default one is set to Enterprise_PageCache_Model_Processor (predictably the same class used to cache the results of a dispatched request).</p>
<p>This is quite important &#8211; if you have a reason to extend the logic in Enterprise_PageCache_Model_Processor (like adding data that forms part of the cache id for a page), you not only have to extend it and rewrite &#8216;enterprise_pagecache/processor&#8217;, but also make sure that it&#8217;s added to this list of request processors so that Magento has a chance of being able to retrieve your items back out of the cache again.</p>
<p>Magento then loops through all the configured request processors, and calls extractContent on each of them. The first thing that this function does is create the cache id based on the request parameters (this happens when the processor is constructed, when the _createRequestIds method is called &#8211; as we saw earlier when the content was being cached in the first place). We check to see if any design changes have been cached for the current page, and then check the configured cache storage to see if we can retrieve the full page content for this request. If we do not get a match at this point, the request is considered a cache miss &#8211; and we return to the run method and start the process of dispatching the request (and potentially populating the cache with the results).</p>
<p>Assuming that we have a cache hit, we decompress it (content will be gzipped whenever possible in the cache storage to minimise space), and the content is processed by _processContent to replace all of the placeholders with separate cached blocks (ie, the catalog/navigation block that we cached separately when putting the page into the cache in the first place).</p>
<p>When writing about how pages are served up from the cache I referred to the configured cache storage. Prior to Magento EE 1.11, the full page cache simply used what you configured in the <cache></cache> section in app/etc/local.xml. From 1.11 this has changed and you must now also have a <full_page_cache></full_page_cache> section in your local.xml configuration (it uses exactly the same options as the <cache></cache> config).</p>
<p>The aim of this post is to give an overview of how page caching works in magento and I am intending on following it up with some more detailed investigations into how more areas of cacheing work. If you have a specific request for more information, please do leave a comment and it may form part of a future blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2012/01/magento-enterprise-pagecache/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Speaking at PHPNW 2011</title>
		<link>http://nocarrier.co.uk/2011/06/speaking-at-phpnw-2011/</link>
		<comments>http://nocarrier.co.uk/2011/06/speaking-at-phpnw-2011/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 19:24:29 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php conference]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=75</guid>
		<description><![CDATA[<p>I&#8217;m delighted to have been accepted to speak on REST and HATEOAS at the PHPNW conference. This marks the start of my speaking &#8216;career&#8217;, something that I have wanted to kick start for some time. The subject matter is something that I am very interested in, and it gives me a chance (and a focus [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m delighted to have been accepted to speak on REST and HATEOAS at the PHPNW conference. This marks the start of my speaking &#8216;career&#8217;, something that I have wanted to kick start for some time. The subject matter is something that I am very interested in, and it gives me a chance (and a focus point) for one of my pet projects that actually gets a little day to day usage over on <a href="http://fdrop.it">http://fdrop.it</a>. It&#8217;s been needing a well designed (and easy to use) API to give it the edge over other file sharing websites, and being accepted to speak at PHPNW on REST has given me the motivation that I need to polish this area of the site and it gives me the opportunity to explain REST with a real life practical example, that people can actually go away and play with.</p>
<p>The abstract is as follows;</p>
<p>REST and HATEOAS: A Case Study</p>
<p>A RESTful API is only truly RESTful if it uses hypermedia to tell us<br />
about all the actions that can be performed on the curent resource,<br />
allowing us to traverse the API from a single entry point.  This<br />
session looks at REST and HATEOAS (Hypermedia As The Engine Of<br />
Application State) to illustrate good service structure.</p>
<p>We&#8217;ll use the RESTful file sharing service fdrop.it to illustrate the<br />
various examples of how this can be used.  This session is recommended<br />
for architects and senior developers alike and will give a good<br />
grounding in writing excellent, self-explanatory RESTful services.</p>
<p>Looking forward to seeing you there!</p>
<p><a href="http://conference.phpnw.org.uk/phpnw11/"><img src="http://conference.phpnw.org.uk/phpnw11/files/2011/05/phpnw11_details_200x144.png" alt="PHPNW 2001" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2011/06/speaking-at-phpnw-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP on Azure</title>
		<link>http://nocarrier.co.uk/2011/02/php-on-azure/</link>
		<comments>http://nocarrier.co.uk/2011/02/php-on-azure/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 12:00:58 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[azure]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=67</guid>
		<description><![CDATA[<p>When I first started out playing with PHP a number of years ago, I did it on my home PC running windows. I remember manually setting up apache (I never tried with IIS), configuring php to work with it and getting a mysql database up and running. The whole process was time consuming and frustrating [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started out playing with PHP a number of years ago, I did it on my home PC running windows. I remember manually setting up apache (I never tried with IIS), configuring php to work with it and getting a mysql database up and running. The whole process was time consuming and frustrating &#8211; without package management it&#8217;s not a particularly pleasant experience.</p>
<p>With Microsofts Azure cloud platform available on a trial [<a href="http://www.microsoft.com/windowsazure/offers/">link</a>], and with PHP Benelux running the PHP on Azure contest [<a href="http://www.phpazurecontest.com/">link</a>] I decided it would be a good opportunity to have another go at using the windows environment as a hosting platform &#8211; though this time using the Web Platform Installer (WebPI) with IIS and SQL Server instead of my traditional LAMP stack.</p>
<p>WebPI promised that this would be a simple process. It certainly looks the part, and has a good range of PHP apps that can be setup out the box. Unfortunately as I was getting all the pre-requisites installed in my Windows 7 VM, the PHP command line tools didn&#8217;t appear to have the Windows Azure SDK available as a dependency. Nor was it available when I searched for it within WebPI.</p>
<p>SQL Server did install ok though, so I followed the manual instructions [<a href="http://azurephp.interoperabilitybridges.com/articles/getting-the-windows-azure-pre-requisites-via-manual-installation">link</a>] to get IIS set up with PHP, and get the SDK installed.</p>
<p>That was fine &#8211; up until the point that I was building my first test deployment to my local development &#8216;cloud&#8217;. It transpires that the package.php script (used to build an azure package out of your php project ready for deployment) assumes that your username does not contain a space. Mine was &#8216;Ben Longden&#8217;.</p>
<p>So I created a new user account and tried again. None of the Azure SDK tools worked under my new user and just claimed that &#8216;A fatal error occured&#8217;, but reinstalling them helped. The next issue was that my new user doesn&#8217;t have access to connect to the SQL server installation (this is something that I have not yet resolved!).</p>
<p>So not plain sailing so far! I found it quite frustrating in all (compared to &#8216;sudo tasksel install lamp-server&#8217;), however my initial deployment to the Azure Cloud went fine in the end, once the environment was set up.</p>
<p>Initial concerns are with how the development process will work. Up next, will be setting up IIS as a development environment that I can work with, and automating the deployment to my local cloud.</p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2011/02/php-on-azure/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHPNW TestFest 2010</title>
		<link>http://nocarrier.co.uk/2010/08/phpnw-testfest-2010/</link>
		<comments>http://nocarrier.co.uk/2010/08/phpnw-testfest-2010/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 09:57:58 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[community]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=42</guid>
		<description><![CDATA[<p> I am very pleased to announce this years PHPNW TestFest over at <a href="http://madlab.org.uk/">MadLab</a> in Manchester. The event will take place on Saturday 11th September from 12pm until sometime around 5-6pm. Lunch will be provided (courtesy of our sponsor, Ibuildings), and I daresay we may wish to make an bit of an evening of [...]]]></description>
			<content:encoded><![CDATA[<p>
I am very pleased to announce this years PHPNW TestFest over at <a href="http://madlab.org.uk/">MadLab</a> in Manchester. The event will take place on Saturday 11th September from 12pm until sometime around 5-6pm. Lunch will be provided (courtesy of our sponsor, Ibuildings), and I daresay we may wish to make an bit of an evening of it at a local bar&#8230;
</p>
<p></p>
<p>
More information on what the php testfest is can be found over at <a href="http://wiki.php.net/qa/testfest-2010"><span style="color: #000000;">http://wiki.php.net/qa/testfest-2010</span></a> and you can register your interest over on upcoming, at <a href="http://upcoming.yahoo.com/event/6621123"><span style="color: #000000;">http://upcoming.yahoo.com/event/6621123</span></a>.
</p>
<p></p>
<p>
All you will need on the day is to bring your laptop. The venue will provide all of the connectivity that we need.
</p>
<p></p>
<p>
Hope to see you there!
</p>
<p></p>
<div><a href="http://nocarrier.co.uk/wp-content/uploads/2010/08/testfest_icon.png"><img class="alignnone size-full wp-image-44" title="testfest_icon" src="http://nocarrier.co.uk/wp-content/uploads/2010/08/testfest_icon.png" alt="" width="124" height="138" /></a><a href="http://nocarrier.co.uk/wp-content/uploads/2010/08/ibuildings_logo_small.jpg"><img class="alignright size-full wp-image-43" title="ibuildings_logo_small" src="http://nocarrier.co.uk/wp-content/uploads/2010/08/ibuildings_logo_small.jpg" alt="" width="170" height="41" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2010/08/phpnw-testfest-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LOLCODE and PHP</title>
		<link>http://nocarrier.co.uk/2010/06/lolcode-and-php/</link>
		<comments>http://nocarrier.co.uk/2010/06/lolcode-and-php/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 09:11:13 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[personal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php lolcode github]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/2010/06/lolcode-and-php/</guid>
		<description><![CDATA[<p>As a proof of concept i&#8217;ve been working on a small LOLCODE (lolcode.com) interpreter thing&#8230; for PHP.</p> <p>Yes, this is a basic implementation of LOLCODE (an interpreted language) written in PHP (an interpreted language).</p> <p>At the moment there&#8217;s enough implemented to parse and run the following&#8230;</p> <p>HAI. BTW THIS IS A COMMENT. VISIBLE &#8220;OH HAI, [...]]]></description>
			<content:encoded><![CDATA[<p>As a proof of concept i&#8217;ve been working on a small LOLCODE (lolcode.com) interpreter thing&#8230; for PHP.</p>
<p>Yes, this is a basic implementation of LOLCODE (an interpreted language) written in PHP (an interpreted language).</p>
<p>At the moment there&#8217;s enough implemented to parse and run the following&#8230;</p>
<p>HAI. BTW THIS IS A COMMENT. VISIBLE &#8220;OH HAI, WORLD&#8221;. KTHXBAI.</p>
<p>You can find the source code up on github at <a href="http://github.com/blongden/lolcode-php">github</a> if you want to have a play (just extend \Lol\Token &#8211; see visible.php for an example).  </p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2010/06/lolcode-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ORM ORLY?</title>
		<link>http://nocarrier.co.uk/2009/11/orm-orly/</link>
		<comments>http://nocarrier.co.uk/2009/11/orm-orly/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 17:41:27 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=34</guid>
		<description><![CDATA[<p>I&#8217;m regularly thinking about how to represent data in a relational database in OO PHP5 that doesn&#8217;t make me walk away feeling like i&#8217;ve just created something that smells bad.</p> <p>The key thing for me is that my code should not care that the data is coming from a relational database. This poses one or [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m regularly thinking about how to represent data in a relational database in OO PHP5 that doesn&#8217;t make me walk away feeling like i&#8217;ve just created something that smells bad.</p>
<p>The key thing for me is that my code should not care that the data is coming from a relational database.  This poses one or two issues.</p>
<ul>
<li> In a relational database, data typically has other &#8216;meta&#8217; data associated with it. Id&#8217;s, timestamps and other snippets of information that are not strictly part of what my object is trying to represent.</li>
<li>If my object is not aware of how it should serialise itself, who is?</li>
</ul>
<p>This of course isn&#8217;t a new problem.  My language of choice (currently PHP5) has many ORM libraries available to it &#8211; Doctrine, Propel and more &#8211; most (or all) of which are loosely based around the Active Record design pattern.</p>
<p>My only problem with these frameworks is that they seem to do too much &#8216;magic&#8217; for me (and I like to retain at least some control over what&#8217;s happening between my app and the database).  Of course, it could also be that I have either not invested enough time in learning to use one of them to it&#8217;s maximum potential.</p>
<p>Despite that, the Active Record pattern appears to be quite a satisfactory way of creating that link between my application, and how it&#8217;s storing it&#8217;s data.  My core objects can exist how I want them to, and their &#8216;datastore&#8217; can be represented by an active record object (who&#8217;s attributes are exactly the same as the columns in the database) on the class itself.  It gives me the degree of separation that i&#8217;ve been looking for.</p>
<p>However there&#8217;s still a piece missing.  My core class still has to contain the relevant logic to load it&#8217;s associated active record.  This suggests some static factory methods (I refer to my earlier comment on things that smell bad!), so i&#8217;m going to create a &#8216;Builder&#8217; for my core object that&#8217;s concerned with marrying up the active record with the core object itself.  Here&#8217;s how it looks (simplified) in a class diagram.</p>
<div id="attachment_35" class="wp-caption alignnone" style="width: 456px"><img class="size-full wp-image-35" title="class-diagram" src="http://nocarrier.co.uk/wp-content/uploads/2009/11/class-diagram.png" alt="ActiveRecord class diagram" width="446" height="336" /><p class="wp-caption-text">ActiveRecord class diagram</p></div>
<p>I&#8217;ve not closed the doors on Doctrine or Propel though, so it&#8217;ll be interesting so see just what an established ORM framework like Doctrine can do for me on top of this basic implementation.</p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2009/11/orm-orly/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Unit testing protected/private methods in a class</title>
		<link>http://nocarrier.co.uk/2009/06/unit-testing-protectedprivate-methods-in-a-class/</link>
		<comments>http://nocarrier.co.uk/2009/06/unit-testing-protectedprivate-methods-in-a-class/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 16:34:27 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[unittests]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=31</guid>
		<description><![CDATA[<p>I think a lot of people when getting into unit testing naturally assume (and are told) that typically, a unit is a single method or function within your code, and each unit should have a unit test.</p> <p>To an extent this is true &#8211; until you are presented with what you do with protected or [...]]]></description>
			<content:encoded><![CDATA[<p>I think a lot of people when getting into unit testing naturally assume (and are told) that typically, a unit is a single method or function within your code, and each unit should have a unit test.</p>
<p>To an extent this is true &#8211; until you are presented with what you do with protected or private methods within classes.</p>
<p>There are two camps of thought on this issue.</p>
<p>One (that I completely and utterly disagree with) says that these methods ARE units in their own right, and should be tested as such (using introspection, or language hacks etc). In PHP this can be accomplished by abusing the __call method in your class (to allow a test suite to call protected or private methods on your class).</p>
<p>The second, is that a &#8216;unit&#8217; is actually a single call to the public interface of your class. The protected and private methods that are called within the class are implementation details and should be allowed to be refactored entirely. Providing the behaviour and the public interface of the class does not change, refactoring does not involve ANY modification to the class itself.</p>
<p>Because the implementation details of a class do not constitute a unit in it&#8217;s own right, testing these methods in isolation are therefore incomplete and actually invalid (as they never have the context in which they are used, and even though your code may show 100% lines of code coverage, the branch coverage will always be far from complete).</p>
<p>So &#8211; if you&#8217;re tempted to create a test for a protected/private method within a class, then you&#8217;re moving away from unit tests and into protecting your implementation using a unit testing framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2009/06/unit-testing-protectedprivate-methods-in-a-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Optimising PHP (a start&#8230;)</title>
		<link>http://nocarrier.co.uk/2009/05/optimising-php-a-start/</link>
		<comments>http://nocarrier.co.uk/2009/05/optimising-php-a-start/#comments</comments>
		<pubDate>Fri, 22 May 2009 09:24:28 +0000</pubDate>
		<dc:creator>blongden</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://nocarrier.co.uk/?p=20</guid>
		<description><![CDATA[<p>Scaling to thousands of users is often a problem for web applications &#8211; and in fact any system that has a sudden large influx of new users. In recent times we have had a situation where we had inherited a fairly simple web application that was massively under performing when a single user accessed a [...]]]></description>
			<content:encoded><![CDATA[<p>Scaling to thousands of users is often a problem for web applications &#8211; and in fact any system that has a sudden large influx of new users. In recent times we have had a situation where we had inherited a fairly simple web application that was massively under performing when a single user accessed a reasonably large dataset from a MySQL database.</p>
<p>Immediately we blamed the database &#8211; it must be the bottleneck &#8211; located on a different server and transferring a result in excess of 10,000 records. But when performing the query from a DB client there was virtually nothing in terms of a delay.</p>
<p>So what was the problem? The code was reasonably simple. An in house database abstraction layer was used to construct a representation of each row returned from the database and stored it in a big array. Common OO style promoted the use of a series of &#8216;setter&#8217; methods to store the data in each constructed object.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$animal</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$mineral</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$vegetable</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setAnimal<span style="color: #009900;">&#40;</span><span style="color: #000088;">$animal</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">animal</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$animal</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setMineral<span style="color: #009900;">&#40;</span><span style="color: #000088;">$mineral</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mineral</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mineral</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setVegetable<span style="color: #009900;">&#40;</span><span style="color: #000088;">$vegetable</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vegetable</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vegetable</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This block of code simulated how each of the objects were being built &#8211; using the data as returned from the database.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">10000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAnimal</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lion'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMineral</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stone'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setVegetable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'potato'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Surprisingly (or perhaps not&#8230;) this code takes around 4.5 seconds to run (obviously depends on hardware!). Quite an overhead when you&#8217;re targeting a 2 seconds per page load time!</p>
<p>Looking at the code &#8211; the constructor is clearly redundant. It&#8217;s not serving any useful purpose. Removing it cut off around half a second of page load time (average).</p>
<p>Removing one of the setters saved another second or so&#8230; removing all the setters (just constructing a blank object 10,000 times cut&#8217;s it down to 1/10th of a second! Could method calls in php be that expensive?</p>
<p>We can create the same result by doing all of this in a constructor &#8211; consider the following.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$animal</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$mineral</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$vegetable</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$animal</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mineral</span><span style="color: #339933;">,</span> <span style="color: #000088;">$vegetable</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">animal</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$animal</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mineral</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$mineral</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vegetable</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vegetable</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">10000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lion'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'stone'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'potato'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This cut&#8217;s things down to just under two seconds &#8211; definitely better &#8211; but not where we want to be. We know that the presence of the constructor (presumably it&#8217;s just the overhead of the method call itself) is costing us some time. What if the class was simply a data container and offered nothing in the way of accessors?</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MyClass
<span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$animal</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$mineral</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$vegetable</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">10000</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">animal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'lion'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mineral</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'stone'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$test</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">vegetable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'potato'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>3/10ths of a second. Ok &#8211; now we are getting somewhere! For 10k results &#8211; this is probably acceptable.</p>
<p>It appears that object creation and method calling is actually quite an expensive operation within PHP &#8211; if we actually had to deal with 100k rows, the fastest way of doing it is always to just use an array. The 10k test completes in less than 1/10th of a second.</p>
<p>A more accurate analysis of just how much object instantiation and method calls cost could be done using xdebug to profile how long each line of code actually takes to execute. But for my purposes, this worked out well.</p>
]]></content:encoded>
			<wfw:commentRss>http://nocarrier.co.uk/2009/05/optimising-php-a-start/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

