<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Planet PHP</title><link rel="alternate" type="text/html" href="http://www.planet-php.net/"/><link rel="self" type="text/html" href="http://www.planet-php.net/atom/"/><subtitle>People blogging about PHP</subtitle><id>http://www.planet-php.net/</id><generator uri="http://planet-php.net/">
            Planet PHP Aggregator
            </generator><updated>2011-05-10T11:43:00Z</updated><link rel="hub" href="http://pubsubhubbub.appspot.com"/><entry><title type="text">CodeIgniter 2.0.2: Cross-Site Scripting (XSS) Fixes And Recommendations</title><link rel="alternate" type="text/html" href="http://blog.astrumfutura.com/2011/05/codeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations/" title="CodeIgniter 2.0.2: Cross-Site Scripting (XSS) Fixes And Recommendations"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~j8p" title="Shortlink to http://blog.astrumfutura.com/2011/05/codeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations/"/><author><name>P&#xE1;draic Brady</name></author><id>http://blog.astrumfutura.com/?p=562</id><updated>2011-05-10T11:43:00Z</updated><published>2011-05-10T11:43:00Z</published><content type="html"><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F05%2Fcodeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations%2F"><br/><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F05%2Fcodeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations%2F&source=padraicb&style=normal&service=bit.ly&service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&hashtags=Cross-Site+Scripting,JavaScript,php,Regular+expression,Security,Vulnerability+%28computing%29&b=2" height="61" width="50"/><br/></a>
		</div>
<p>As many of my readers know, <a href="http://blog.astrumfutura.com/2011/03/regex-html-sanitisation-off-with-its-head/">I have a keen dislike for regular expression based html sanitisation</a>. Regular expressions simply do not understand html’s nested nature and the numerous possible html/CSS standards it must abide by. The result is that far too many developers try to program this understanding (and unfortunately their lack of comprehensive understanding) into home grown sanitisers using as little code and tests as possible.  It’s a horrendous and reprehensible practice that has created a large field of so-called sanitisers and XSS cleaners which are riddled with obvious vulnerabilities despite all their sincere and utterly false claims to the contrary. The perception of safety they create is almost always a fantasy. As I’ve said before, this serves only one purpose – to lend support to claims that PHP is insecure. And why disagree given PHP’s prominence on the internet and this continuing refusal by developers to just do the right thing and use a secure solution that really does work?</p>
<p>Since I’ve completed my research into a broad set of these, for now, I’ll close with a final example given its widespread usage, confusing documentation and lack of a clear disclosure to date of security vulnerabilities.</p>
<p>On April 7, EllisLab <a href="http://codeigniter.com/news/codeigniter_2.0.2_released/">released CodeIgniter 2.0.2</a> as a security maintenance release prompted by a report I sent to EllisLab shortly before St. Paddy’s Day (around mid-March). That report indicated the expected response and my own disclosure policy. This blog post is being published in accordance with those. The disclosure to date of the vulnerabilities afflicting previous CodeIgniter versions is mentioned only in <a href="http://codeigniter.com/news/codeigniter_2.0.2_released/">the CodeIgniter 2.0.2 news release</a> (from April 7) as follows:</p>
<blockquote><p>An update to both CodeIgniter Reactor and CodeIgniter Core (v 2.0.1) was released today. This is a security maintenance release and is a recommended update for all sites. The security fix patches a small vulnerability in the cross site scripting filter.</p></blockquote>
<p>EllisLab’s news release for CodeIgniter 2.0.2 makes mention of “a small vulnerability”. This small vulnerability is mentioned no where else (not even the actual changelog for 2.0.2). In reality, I reported seven distinct vulnerabilities across two classes. These vulnerabilities might allow an attacker to inject arbitrary html, CSS or Javascript, i.e. <a class="zem_slink" title="Cross-site scripting" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross-Site Scripting</a> (XSS) into an application’s output. It would be nice if, in the future, EllisLab aim for more accuracy in their news releases and disclosed both the number and nature of the security vulnerabilities fixed in their release changelogs.</p>
<p>Users of CodeIgniter 2.0.x and 1.7.x are strongly urged to upgrade to CodeIgniter 2.0.2 (or later) as soon as possible to avail of these critical security fixes.</p>
<p>In addition, users are urged to follow some basic steps when writing or updating CodeIgniter applications:</p>
<ol><li>Escape ALL data being injected into views using PHP’s htmlspecialchars()  function, remembering to pass the <a class="zem_slink" title="Character encoding" rel="wikipedia" href="http://en.wikipedia.org/wiki/Character_encoding">character encoding</a> being used as the  third parameter. A helper function may be useful to keep the typing to a  minimum.</li>
<li>Use <a href="http://htmlpurifier.org/">htmlPurifier</a> when you need to sanitise html data or user input such as html  comments, html emails, or RSS/Atom content (basically any html you do  not explicitly generate yourself!).</li>
<li>Ensure that all html pages are served with a valid Content-Type HTTP  header and/or a meta tag equivalent which also declares the charset for  that page. Note that html5 offers a separate charset element for this  purpose. This helps prevent character encoding based XSS attacks by  informing the browser of the correct character en</li></ol><p><i>Truncated by Planet PHP, read more at <a href="http://blog.astrumfutura.com/2011/05/codeigniter-2-0-2-cross-site-scripting-xss-fixes-and-recommendations/">the original</a> (another 1696 bytes)</i></p>]]></content></entry><entry><title type="text">Regex html Sanitisation: Off With Its Head!</title><link rel="alternate" type="text/html" href="http://blog.astrumfutura.com/2011/03/regex-html-sanitisation-off-with-its-head/" title="Regex html Sanitisation: Off With Its Head!"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~j4E" title="Shortlink to http://blog.astrumfutura.com/2011/03/regex-html-sanitisation-off-with-its-head/"/><author><name>P&#xE1;draic Brady</name></author><id>http://blog.astrumfutura.com/?p=453</id><updated>2011-03-17T16:58:00Z</updated><published>2011-03-17T16:58:00Z</published><content type="html"><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F03%2Fregex-html-sanitisation-off-with-its-head%2F"><br/><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.astrumfutura.com%2F2011%2F03%2Fregex-html-sanitisation-off-with-its-head%2F&source=padraicb&style=normal&service=bit.ly&service_api=padraic%3AR_94101570b7e190f3de921bc15bb9438d&hashtags=Cross-Site+Scripting,html,List+of+XML+and+html+character+entity+references,php,Regular+expression,UTF-8&b=2" height="61" width="50"/><br/></a>
		</div>
<div class="zemanta-img" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 310px"><a href="http://commons.wikipedia.org/wiki/File:Guillotine_%28PSF%29.png"><img title="Guillotine" src="http://upload.wikimedia.org/wikipedia/commons/thumb/0/05/Guillotine_%28PSF%29.png/300px-Guillotine_%28PSF%29.png" alt="Guillotine" width="300" height="232"/></a><p class="wp-caption-text">Image via Wikipedia</p></div>
</div>
<p>A long time ago someone coined the phrase <a class="zem_slink" title="Cross-site scripting" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cross-site_scripting">Cross-Site Scripting</a> and it became popularly abbreviated as XSS (the X was suggested to avoid confusion with CSS). XSS is a family of vulnerabilities that allows an attacker to inject arbitrary content, often Javascript, into the output (not necessarily html) viewed by users of a web application. These injections tend to do bad things. It is a plague upon web applications and not just those written in PHP.</p>
<h2>Defeating Cross-Site Scripting</h2>
<p>The solutions which prevent and defend against XSS in html are commonly known:</p>
<p>If you inject data into html (e.g. a template), and cannot be 110% sure it never crossed paths with a malicious user, you escape it. In PHP this means passing such data through a function like PHP’s htmlspecialchars(), always remembering to pass the character encoding of your output as the third parameter. An alternative exists for cases where you do not determine the html markup of output, for example, when aggregating content from RSS or Atom feeds, from web service API responses, from html emails, from user comments where html is allowed, or even from the output of html transformers such as libraries which translate <a class="zem_slink" title="BBCode" rel="wikipedia" href="http://en.wikipedia.org/wiki/BBCode">BBCode</a>, Markdown or some other intermediate format into html. These alternatives are usually called html Sanitisers or XSS Cleaners.</p>
<p>The first case is simple, easy to execute, and very difficult to spoof. Its main problem is that it requires foreknowledge of the character encoding of the output since <a class="zem_slink" title="List of XML and html character entity references" rel="wikipedia" href="http://en.wikipedia.org/wiki/List_of_XML_and_html_character_entity_references">html special characters</a> may differ between encodings. A simple example of this encoding difference is found by comparing <a class="zem_slink" title="UTF-8" rel="wikipedia" href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> and <span class="zem_slink">UTF-7</span>. Whereas UTF-8 is <a class="zem_slink" title="ASCII" rel="wikipedia" href="http://en.wikipedia.org/wiki/ASCII">US ASCII</a> compatible, UTF-7 is not. Escaping UTF-7 markup as if it were UTF-8 would cause the escaping mechanism to fail in detecting the angular brackets that html tags are enclosed by since they occupy different points in UTF-7. Obviously, such a failure is a potential disaster – especially if your output supports a UTF-7 encoding, or if it never specifies a character encoding at all either via a header or a <a class="zem_slink" title="Meta element" rel="wikipedia" href="http://en.wikipedia.org/wiki/Meta_element">html meta</a> tag since this may allow some browsers (cough…Internet Explorer) to guess the wrong encoding to use.</p>
<p>The second case is complex. There are no easy solutions or single paragraph pearls of wisdom you can rely on. Instead of a simple function, you need a library of code capable of parsing html and handling character encoding differences. Then you need a friendly API so programmers aren’t buried in the complexity of the task, a whitelist and whitelist limiter to defend against misconfiguration, knowledge of every html standard since the dawn of time and up to the minute advice on emerging html quirks across all browsers (even the ones you think are no longer used). After that, you are not done. You’re only beginning. You’re going to need a parser and lexer, a character encoding handler, a html tidier so you don’t break stuff, a possy of XSS wizards to tell you when you’re failing, and enough unit tests that if Sebastian Bergmann knew what you were doing, even he would jump </p><p><i>Truncated by Planet PHP, read more at <a href="http://blog.astrumfutura.com/2011/03/regex-html-sanitisation-off-with-its-head/">the original</a> (another 7585 bytes)</i></p>]]></content></entry><entry><title type="text">Using the Symfony2 console</title><link rel="alternate" type="text/html" href="http://blog.liip.ch/archive/2010/12/21/using-the-symfony2-console.html" title="Using the Symfony2 console"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~jVT" title="Shortlink to http://blog.liip.ch/archive/2010/12/21/using-the-symfony2-console.html"/><author><name>Liip </name></author><id>http://blog.liip.ch/archive/id/5066/</id><updated>2010-12-21T12:34:00Z</updated><published>2010-12-21T12:34:00Z</published><content type="html"><![CDATA[<div>It is always almost the same story: "As a customer I want to import data from the the superseded system in to the newly build environment".<br/>
So whats the deal? Building the new system based on the database structure to make the import as easy as possible? No, way to many drawbacks and since we have our lessons learned we know that flexibility matters and we'd rather go for a better fitting database design.</div>
<h2>Web-services for the reScue</h2>
<div>As for the flexibility decoupling is the magic word. A web-service might be the right answer to this question. Why? Because there are a huge number of standards (HTTP, RSS, ATOM, XML-RPC, AJAX, …) supporting this approach, they are locally independend, and they really easy to implement. At least the old system had a RSS-feed in place. So I started investigating if there is a way in Symfony2 to call recieve data from a feed.</div>
<h2>Do you know <em>app/console</em>?</h2>
<div>Seems at least some people had the same idea as I had, retrieving data from a feed via HTTP GET. So Symfony2 comes up with a nice litte wrapper - the <em>console</em>. Unfortunately the <a href="http://docs.symfony-reloaded.org/quick_tour/the_architecture.html?highlight=console#the-command-line-interface" target="_blank">documentation</a> on the website only gives a very brief introduction to it.<br/>
Located in the <em>app</em> directory of your project it is ready to be called as soon your Symfony2 installation is ready to be used. Executing it on the command line without an argument it exposes its help page.</div>
<div/>
<div/>
<pre>
$ php app/console
Symfony version 2.0.0-DEV - app

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v Increase verbosity of messages.
  --version        -V Display this program version.
  --ansi           -a Force ANSI output.
  --no-interaction -n Do not ask any interactive question.
  --shell          -s Launch the shell.

Available commands:
  help          Displays help for a command (?)
  list          Lists commands
assets
  :install    
init
  :bundle
router
  :debug        Displays current routes for an application
  :dump-apache  Dumps all routes as Apache rewrite rules
</pre>
<div/>
<div>The console provides you with almost everything necessary to run your bundle from the command line. It is even capable of creating a base setup of a new bundle using the <em>init:bundle</em> command. For example:</div>
<div/>
<div/>
<div/>
<pre>
$>php app/console init:bundle Application/MyBundle</pre>
<p/>
<h2>Making you bundle accessible from the cli</h2>
<div>Since the search in the online documentation directly passed me to the Doctrine integration of Symfony2 using the console to do some magic handling the cache or setting up the Doctrine environment I found this as a nice source of information how to do this. Also my college <a href="http://seld.be" target="_blank">Jordi</a> was very helpful getting a clue of all this.</div>
<h3>Preparing your Bundle</h3>
<div>Basically you just have to create a directory in your top level of your Bundle name <em>Command</em> and place every class file in to be available from the command line. Surely the filename and the name of the containing class have to end with <emcommand> (e.g. 'ImportCommand'). The nice thing with his is that Symfony2 finds your class on its own. So no further configuration has to be done.</emcommand></div>
<h2>Adding functionality</h2>
<div>Before we could start implementing what your cli representation of your Bundle shall do we need to set some  basics first.<br/>
For starters your command class has to extends<em> \Symfony\Bundle\FrameworkBundle\Command\Command </em>to integrate well into the Symfony2 environment.<br/>
Doing this you enables you to override the <em>execute()</em> and <em>configure()</em> functions. The names of he methods will let your guess their function.</div>
<h3>Configuration</h3>
<div>I earlier quoted that there is no further configuration is to be done. This is true in case of the registration of your command in Symfony2. Surely there is some configuration to be done in terms of name, arguments, description, and perhaps a little help text. The extended class (\Symfony\Bundle\FrameworkBundle\Command\Command) provides you with a set of setter methods to add the mentioned and more information to the configuration of your command. Since Symfony2 is still under development please checkout the <a href="http://api.symfony-reloaded.org/PR4/Symfony/Bundle/FrameworkBundle/Command/Command.html" target="_blank">API-documentation</a> for a conclusive list of those setters.</div>
<div>The Name is used as the <em>command</em> in the console arguments to address your implementation. You should take care that this is all unique. One way to assure this is to add a prefix divided by colon from the real name (e.g 'myProjectName:impo</div><p><i>Truncated by Planet PHP, read more at <a href="http://blog.liip.ch/archive/2010/12/21/using-the-symfony2-console.html">the original</a> (another 3270 bytes)</i></p>]]></content></entry><entry><title type="text">Behind The New VPR Homepage</title><link rel="alternate" type="text/html" href="http://bradley-holt.com/2010/10/behind-the-new-vpr-homepage/" title="Behind The New VPR Homepage"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~jPE" title="Shortlink to http://bradley-holt.com/2010/10/behind-the-new-vpr-homepage/"/><author><name>Bradley Holt</name></author><id>http://bradley-holt.com/?p=888</id><updated>2010-10-11T15:09:00Z</updated><published>2010-10-11T15:09:00Z</published><content type="html"><![CDATA[<p><a href="http://foundline.com/">Found Line</a> had the privilege of designing and developing <a href="http://www.vpr.net/">Vermont Public Radio</a>‘s (VPR) new homepage. VPR’s Online Manager, Jonathan Butler, wrote a blog post about how the <a href="http://vprblog.blogspot.com/2010/10/new-vprnet-homepage.html">redesigned homepage delivers more content to VPR.net visitors.</a> Here I’ll talk about the technology behind this new homepage.</p>
<h3>Atom Syndication Format</h3>
<p>Most of VPR’s web content is currently stored in a proprietary content management system (CMS). The first step was publishing the needed content from the CMS out into an open format. VPR’s Dan Allen published from the CMS <a href="http://www.atomenabled.org/">Atom</a> feeds of the various content we would need for the new homepage.</p>
<h3>PHP and Zend Framework</h3>
<p>Once we had the needed Atom feeds, we created a <a href="http://framework.zend.com/">Zend Framework</a> web application to import these feeds. Components such as <a href="http://framework.zend.com/manual/en/zend.feed.reader.html">Zend_Feed_Reader</a> made the job easier. The weather data comes from the National Oceanic and Atmospheric Administration’s (NOAA) National Weather Service’s <a href="http://www.weather.gov/forecasts/xml/rest.php">National Digital Forecast Database XML/REST Service</a>. The market data comes from the <a href="http://code.google.com/apis/finance/">Google Finance API</a>.</p>
<h3>CouchDB</h3>
<p>All of the data (except for weather, which is pulled directly with a bit of caching) is stored in <a href="http://couchdb.apache.org/">CouchDB</a>. Since we’re storing documents with varying metadata (i.e. Atom entries) choosing a document-oriented database made a lot of sense. CouchDB’s map/reduce views make for very efficient queries. Its RESTful HTTP API provides a lot of options for scaling and caching. We’re caching documents within the Zend Framework application and conditionally requesting these documents from CouchDB with ETags when a cache is available. The current cache is simply file-based but we’re considering using <a href="http://memcached.org/">Memcached</a> for even better performance. On a related note, the homepage itself also supports conditional HTTP requests.</p>
<h3>Apache and nginx</h3>
<p>We had the pleasure of working with another great Vermont company, <a href="http://www.clearbearing.com/">ClearBearing</a>, on this project. ClearBearing handles the infrastructure layer for <a href="http://www.vpr.net/">VPR.net</a>. The current website was (and still is) served up by <a href="http://httpd.apache.org/">Apache</a>. ClearBearing already had <a href="http://nginx.org/">nginx</a> in place as a reverse proxy to handle caching. Since we weren’t replacing the entire CMS we needed a way for the existing CMS and this new application to coexist. We decided to host the new application separately (still administered by ClearBearing) and reverse proxy requests for certain URIs (primarily the homepage) to the new application. This provides a clean separation between the new application and the existing CMS while still allowing for them to be hosted on the same domain from an end-user perspective.</p>
<h3>Licensing</h3>
<p>You’ll notice that all of the standards used are open standards and all of the technologies used are free and open source software. Additionally, all of the code we have written for VPR is licensed to them under the permissive <a href="http://www.opensource.org/licenses/bsd-license.php">New BSD License</a>. This means that VPR is free to use this code however they want, study and modify the code, and redistribute the code as-is or modified. They can do all of this without paying additional licensing fees.</p>
<h3>Design</h3>
<p>While this post is primarily about the technology behind VPR’s new homepage, I should mention that Found Line’s <a href="http://foundline.com/people/jason-pelletier">Jason Pelletier</a> designed the new homepage and implemented all of its html and CSS. We worked closely with Jonathan Butler and John Van Hoesen, Vice President for News & Programming, to make sure the new design meets the needs of website visitors and the organization.</p>
<h3>Next Steps</h3>
<p>The launch of this new homepage was just one iteration with many more to come. As Jonathan Butler mentioned in his blog post, VPR has plans to further improve online services for their listeners. Look for a redesigned VPR Classical page soon. There are also plans for better mobile access to VPR and VPR Classical programming. Fortunately much of the work that has been done can be leveraged to create additional online services for VPR’s listeners.</p>
<p>A special thanks for the <a href="http://www.vpr.net/support/">support of VPR’s listeners</a>—you made this new homepage possible! If you have questions, comments, complaints, or suggestions about the new homepage then please <a href="http://www.vpr.net/inside_vpr/contact_us/?subject=VPR+Homepage">contact VPR</a> directly with your feedback (although you’re welcome to comment here as well).</p>
]]></content></entry><entry><title type="text">Creating Zend_Tool Providers</title><link rel="alternate" type="text/html" href="http://weierophinney.net/matthew/archives/242-Creating-Zend_Tool-Providers.html" title="Creating Zend_Tool Providers"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~jvI" title="Shortlink to http://weierophinney.net/matthew/archives/242-Creating-Zend_Tool-Providers.html"/><author><name>Matthew Weier O'Phinney</name></author><id>http://weierophinney.net/matthew/archives/242-guid.html</id><updated>2010-07-01T13:05:00Z</updated><published>2010-07-01T13:05:00Z</published><content type="html"><![CDATA[
    <p>
    When I was at <a href="http://www.symfony-live.com/">Symfony Live</a> this
    past February, I assisted <a
        href="http://www.leftontheweb.com/">Stefan Koopmanschap</a>
    in a full-day workshop on integrating Zend Framework in Symfony
    applications. During that workshop, Stefan demonstrated creating Symfony
    "tasks". These are classes that tie in to the Symfony command-line
    tooling -- basically allowing you to tie in to the CLI tool in order to
    create cronjobs, migration scripts, etc.
</p>

<p>
    Of course, Zend Framework has an analogue to Symfony tasks in the <a
        href="http://framework.zend.com/manual/en/zend.tool.html">Zend_Tool</a>
    component's "providers". In this post, I'll demonstrate how you can create a
    simple provider that will return the most recent entry from an RSS or Atom
    feed. 
</p>
 <br /><a href="http://weierophinney.net/matthew/archives/242-Creating-Zend_Tool-Providers.html#extended">Continue reading "Creating Zend_Tool Providers"</a>
    ]]></content></entry><entry><title type="text">Switzerland, Microsoft and the JumpInCamp!</title><link rel="alternate" type="text/html" href="http://blog.echolibre.com/2010/04/switzerland-microsoft-and-the-jumpincamp/" title="Switzerland, Microsoft and the JumpInCamp!"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~jnY" title="Shortlink to http://blog.echolibre.com/2010/04/switzerland-microsoft-and-the-jumpincamp/"/><author><name>Echolibre</name></author><id>http://blog.echolibre.com/?p=898</id><updated>2010-04-15T16:13:00Z</updated><published>2010-04-15T16:13:00Z</published><content type="html"><![CDATA[<p style="text-align: justify;">As some of you may know from the tweets I’ve been posting for nearly 3 weeks now, I was invited to attend the very first edition of the <a title="Microsoft JumpInCamp" href="http://jumpincamp.com">JumpInCamp</a> organized by Microsoft in April 2010.</p>
<p style="text-align: justify;">The goal of this camp was to get the European PHP community leaders together and learn about the new products and new ideas Microsoft are working on. For those of you who read about the <a title="Microsoft Web Developer Summit" href="http://blog.echolibre.com/2009/12/microsoft-web-developer-summit/">Microsoft web developer summit</a> that took place in Redmond in December 2009 you might think it was the same thing however you would be utterly wrong.</p>
<p style="text-align: justify;">While the camp in Redmond was very informative and we are learnt a great deal of new features coming up with Microsoft, it was vastly different than the <a title="Microsoft JumpInCamp" href="http://jumpincamp.com">JumpinCamp</a> in Zurich where the focus of the camp was to get the developers to interact with the actual Microsoft developers instead of only learning about new features. The point of the JumpinCamp was to get your hands dirty in code so we all got a few hours of lectures, then sat down and worked on either implementing those solutions into our respective Open Source projects or even discussed and raised concerns we might have regarding some of their products.</p>
<p>I thought it might be nice to share some of the projects I’ve started working on while I was over there and what I had interests in:<br/><span id="more-898"/></p>
<h2 style="text-align: justify;">OData</h2>
<p style="text-align: justify;">After meeting with Claudio Caldato, the program manager for the Interoperability team, we went over the <a title="The Open Data Protocol" href="http://odata.org">OData</a> project and after looking at the position of <a title="The Open Data Protocol" href="http://odata.org">OData</a> and it’s potential, I decided to join the team and start by developing a <a title="PEAR PHP" href="http://pear.php.net">PEAR</a> package that will allow producers to publish valid OData <a title="Atom Pub" href="http://bitworking.org/projects/atom/rfc5023.html">Atom Pub feeds</a> and serve as a base driver for the PHP community (Which could be easily ported to <a title="Zend Framework" href="http://zendframework.com/">Zend Framework</a>, <a title="The Symfony Project" href="http://www.symfony-project.org/">Symfony</a>, <a title="Lithium Rad PHP Framework!" href="http://lithify.me">Lithium</a>, etc.)</p>
<p style="text-align: justify;">Obviously one of the reason for and OData producer package is to be able to make all the Frapi users potential OData producers. Moreover, as some of you know, sometimes I get into rants about web semantics and microformat. When I saw OData I realized that we could potentially bring some microformat standards within OData Atom Pub feeds (Or JSON Feeds).</p>
<p style="text-align: justify;">Another thing that lit me up was the JSON feed. As some of you may have read on this very blog a few months ago I wrote an article about having something called <a title="Practical Json Format Standard" href="http://blog.echolibre.com/2009/04/practical-json-format-standard/">PJSF</a> which basically is the concept or idea of defining a standard format for JSON feeds. When I saw that OData has the ability to generate JSON feeds, I obviously jumped on the occasion of making a difference in the semantics world <img src="http://blog.echolibre.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley"/></p>
<h2 style="text-align: justify;">Azure</h2>
<p style="text-align: justify;"><a title="Microsoft Azure" href="http://www.microsoft.com/windowsazure/ ">Azure</a> basically is a platform that offers a flexible, familiar environment for developers to create cloud applications and services. With Windows Azure, you can shorten your time to market and adapt as demand for your service grows.</p>
<p style="text-align: justify;">What does is really mean? Azure is an <strong>all-in-one cloud solution</strong>. Even though the concepts are a bit arduous to grasp, we can all thank <a title="Josh Holmes Blog And Azure Resource" href="http://www.joshholmes.com/blog/">Josh Holmes</a> and <a title="Maarten Balliauw Blog" href="http://blog.maartenballiauw.be">Maarten Balliauw</a> for their essential presence at this camp to help us with all the questions we had and their thorough understanding of their baby (Azure).</p>
<p style="text-align: justify;">Azure was another thing that sprung to my mind for <a title="Frapi Open Source API Framework" href="http://getfrapi.com">Frapi</a>. What if we could get our Frapi customers to be deployed directly into the cloud? Obviously it’s possible to hack around all the possible Amazon web services and to get somewhat arranged so our customers woul</p><p><i>Truncated by Planet PHP, read more at <a href="http://blog.echolibre.com/2010/04/switzerland-microsoft-and-the-jumpincamp/">the original</a> (another 4879 bytes)</i></p>]]></content></entry><entry><title type="text">Using PHP DOM With XPath</title><link rel="alternate" type="text/html" href="http://www.a-basketful-of-papayas.net/2010/04/using-php-dom-with-xpath.html" title="Using PHP DOM With XPath"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~jnd" title="Shortlink to http://www.a-basketful-of-papayas.net/2010/04/using-php-dom-with-xpath.html"/><author><name>Thomas Weinert</name></author><id>http://www.a-basketful-of-papayas.net/2010/04/using-php-dom-with-xpath.html</id><updated>2010-04-10T10:54:00Z</updated><published>2010-04-10T10:54:00Z</published><content type="html"><![CDATA[<p>Often I hear people say "We use SimpleXML, because DOM is so noisy and complex". Well, I don't think so. This article explains how you can parse a XML (an Atom feed) using the PHP DOM extension. No other libraries are involved.</p>

<h3>Load the feed</h3>
<p>To load the feed, you need to create an new DOMDocument document using it's load() method. This works with the PHP stream wrappers, so you can load local files or urls. DOMdocument, has dedicated methos for XML strings and html files and strings, too.</p>
<p>
<code>
$feed = new DOMDocument();<br/>
$feed->load('http://www.a-basketful-of-papayas.net/feeds/posts/default');<br/>
...<br/></code>
</p>
<p>If here is any problem with the resource, PHP will output error messages. You can use <tt>libxml_use_internal_errors()</tt> to block them. With <tt>libxml_clear_errors()</tt> the internal error list is cleared, <tt>libxml_get_errors()</tt> returns them so you could implemented you own error handling. Just ignore them for now:</p>
<p><code>
$errorSetting = libxml_use_internal_errors(TRUE);<br/>
$feed = new DOMDocument();<br/>
$feed->load('http://www.a-basketful-of-papayas.net/feeds/posts/default');<br/>
libxml_clear_errors();<br/>
libxml_use_internal_errors($errorSetting);<br/>
...<br/></code></p>
<p>In the next step you should check if you got some content. I use the documentElement property for this. If it is not here, the feed has to be invalid because any XML needs at least one element node.</p>
<p><code>
if (isset($feed->documentElement)) {<br/>
  ...<br/>
} else {<br/>
  echo 'Invalid feed.';<br/>
}<br/></code></p>
<h3>Initialize XPath</h3>
<p>Now a XPath object is needed to execute expressions. Atom feeds make use of namespaces, often declaring the atom namespace as default. But in XPath you have no default namespace, you need to register the namespace with an arbitrary prefix. It does not have to be the same prefix used in the XML file. It can't for the default namespace obviously because it has no prefix in the XML file.</p>
<p><code>
...<br/>
$xpath = new DOMXPath($feed);<br/>
$xpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom');<br/>
...<br/></code></p>
<p>If you load html into the DOMDocument using the special methods, all namespaces are ignored. You can skip the registration in this case.</p>

<h3>Executing XPath Expressions</h3>
<p>The DOMXPath object has two methods for executing xpath expressions. One is <tt>query()</tt>, it always returns a DOMNodelist. You should use the second one: <tt>evaluate()</tt>. It will return DOMNodelist objects by default, but depending on the expression it can return other types, too. With <tt>evaluate()</tt> you have direct access to the title text, it will return an empty string if the feed has no title.</p>
<p>The code selects the element nodes in the registered namespace and casts them to string.</p>
<p><code>
...<br/>
echo $xpath->evaluate('string(/atom:feed/atom:title)'), "\n";<br/>
echo $xpath->evaluate('string(/atom:feed/atom:subtitle)'), "\n";<br/>
...<br/></code></p>
<p>Next we will loop over all entries. A DOMNodelist works with foreach, the expression will return an empty list if it does not match, so no additional checking is needed. Inside the loop the entry node is used as a context argument for <tt>evaluate()</tt>.</p>
<p><code>
...<br/>
foreach ($xpath->evaluate('//atom:entry') as $entryNode) {<br/>
  echo $xpath->evaluate('string(atom:title)', $entryNode), "\n";<br/>
  echo $xpath->evaluate(<br/>
    'string(atom:link[@rel="alternate" and @type="text/html"][1]/@href)',<br/>
    $entryNode<br/>
    ), "\n";<br/>
  echo "\n";<br/>
}<br/>
...<br/></code></p>

<h3>Conditions</h3>

<p>XPath expression can be conditions. It can be used to check if a entry has categories (tags). The return value of the following expression is a boolean value.</p>
<p><code>
...
if ($xpath->evaluate('count(atom:category) > 0', $entryNode)) {
  ...
}
...
</code></p>

<h3>Loop over attributes</h3>

<p>Each entry can have several categories. The title of the category is in it's attribute "term". You can select these attributes directly into a list.</p>
<p><code>
echo 'Categories: ';<br/>
foreach ($xpath->evaluate('atom:category/@term', $entryNode) as $index => $categoryAttribute) {<br/>
  if ($index > 0) {<br/>
    echo ', ';<br/>
  }<br/>
  echo $categoryAttribute->value;<br/>
}<br/>
echo "\n";<br/></code></p>

<h3>Complete Example</h3>
<p>Here is the full script. Be aware that it outputs text. If you execute it using a webserver (and not the command line), you should add a <tt>header('Content-Type: text/plain')</tt> to the top.</p>
<p><code>
&lt;?php<br/>
$errorSetting = libxml_use_internal_errors(TRUE);<br/>
$feed = new DOMDocument();<br/>
$feed->load('http://www.a-basketful-of-papayas.net/feeds/posts/default');<br/>
libxml_clear_errors();<br/>
libxml_use_internal_errors($erro</code></p><p><i>Truncated by Planet PHP, read more at <a href="http://www.a-basketful-of-papayas.net/2010/04/using-php-dom-with-xpath.html">the original</a> (another 2150 bytes)</i></p>]]></content></entry><entry><title type="text">Pirum, the Simple PEAR Channel Server Manager</title><link rel="alternate" type="text/html" href="http://fabien.potencier.org/article/38/pirum-the-simple-pear-channel-server-manager" title="Pirum, the Simple PEAR Channel Server Manager"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~i9Y" title="Shortlink to http://fabien.potencier.org/article/38/pirum-the-simple-pear-channel-server-manager"/><author><name>Fabien Potencier</name></author><id>http://fabien.potencier.org/article/38/pirum-the-simple-pear-channel-server-manager</id><updated>2009-11-28T07:50:00Z</updated><published>2009-11-28T07:50:00Z</published><content type="html"><![CDATA[
    <p>Some weeks ago during the Zend Conference, I
<a href="http://twitter.com/fabpot/status/4969508481">quietly</a> released
<a href="http://www.pirum-project.org/">Pirum</a>, a simple PEAR channel server manager.
As some people talk about it on "social
<a href="http://twitter.com/s_bergmann/statuses/6121431277">networks</a>", I thought I
should write an official announcement on my blog to explain where I come from.</p>

<p>A PEAR channel server allows you to install PEAR packages with the PEAR
command line. You are probably already familiar with it as it comes bundled
with most PHP installations:</p>

<pre class="command-line"><code>$ pear install ...
</code></pre>

<p>Pirum comes from my frustration with the current state of PEAR channel
servers. Beside big Open-Source projects like
<a href="http://www.symfony-project.org/">symfony</a>, I'm also responsible for smaller
projects (like <a href="http://www.twig-project.org/">Twig</a>, or <a href="http://www.swiftmailer.org/">Swift Mailer</a>).
But for all my software, I like to provide different way
of installing them: directly from SVN via <code>svn:externals</code>,
from my <a href="http://www.github.com/fabpot">Git</a> mirrors, from an
archive to download, or with the PEAR command line.</p>

<p>Except for the PEAR package installation, the other ones are quite easy to
setup and automate. But providing a PEAR channel proves to be more involving.
The only serious PEAR channel server I'm aware of is
<a href="http://greg.chiaraquartet.net/archives/123-Setting-up-your-own-PEAR-channel-with-Chiara_PEAR_Server-the-official-way.html">Chiara_PEAR_Channel</a>
from Greg Beaver. This is the software I used for symfony for four years. It
works really well, but is a bit cumbersome to setup for smaller projects (it
needs a database, and you need to configure some categories, the contributors
for the project, and more). That's fine for <a href="http://pear.php.net">PEAR</a>
itself, but frankly, for the rest of us, that's just too much.</p>

<p>As a matter of fact, hosting a PEAR channel server is super simple. It's all
about static files. That's right, even if you need some sort of PHP scripts to
maintain a PEAR channel server, the frontend used by the PEAR command line
tool can only be static files (mainly XML ones). And <code>Chiara_PEAR_Server</code>
works exactly like this. The backend, done in PHP, is where you maintain your
packages, and it generates the frontend, a bunch of static files for the
frontend. That's a really great architecture as it allows to scale very
easily. For instance, you should probably be able to host a PEAR channel
server on a CDN line Amazon S3 in a matter of minutes.</p>

<p>Thanks to this decoupled and simple architecture, I wrote some PHP scripts to
manage a PEAR channel server for the symfony
<a href="http://www.symfony-project.org/plugins/">plugins</a> two years ago.</p>

<p>The idea for Pirum came when I started the
<a href="http://www.twig-project.org/">Twig</a> project. Obviously, I wanted a PEAR
channel server for Twig, but I really did not want to use
<code>Chiara_PEAR_Server</code>. So I started to hack my own and Pirum was born.</p>

<p>Pirum lets you setup PEAR channel servers in a matter of minutes. Pirum is
best suited when you want to create small PEAR channels for a few packages
written by a few developers.</p>

<p>Pirum consists of just one file, a command line tool, written in PHP. There is
no external dependencies, no not need for a database, no need to setup
credentials, and nothing need to be installed or configured.</p>

<p>Installing Pirum is as simple as downloading the
<a href="http://github.com/fabpot/Pirum/raw/master/pirum">pirum</a> file and saving it
where you see fit.</p>

<blockquote class="note"><p>
  Of course, Pirum itself uses Pirum to provide a PEAR channel
  <a href="http://pear.pirum-project.org/">server</a> for itself!</p>
</blockquote>

<p>Even if Pirum only consists of just one file, it comes with a lot of great
features:</p>

<p>Besides its size and simplicity, Pirum is packed with a lot of features:</p>

<ul>
<li><p>It creates a full-featured PEAR channel server useable by any PEAR CLI;</p></li>
<li><p>Each channel has an html page describing the server and the packages it
hosts;</p></li>
<li><p>New releases can be tracked by subscribing to an Atom feed.</p></li>
</ul>

<p>Of course, it also comes with some limitations:</p>

<ul>
<li><p>No support for fallback PEAR channel servers;</p></li>
<li><p>No category management (all packages are under a "default" category);</p></li>
<li><p>No web interface for managing the packages.</p></li>
</ul>

<p>You can find more information about using Pirum on its official
<a href="http://www.pirum-project.org/">website</a>.</p>

<p>Pirum is already used by the following Open-Source projects:</p>

<ul>
<li><p><a href="http://www.symfony-project.org/">Symfony</a></p></li>
<li><p><a href="http://pear.phpunit.de/">PHPUnit</a></p></li>
<li><p><a href="http://www.swiftmailer.org/">Swift Mailer</a></p></li>
<li><p><a href="http://www.twig-project.org/">Twig</a></p></li>
<li><p><a href="http://www.fluentdom.org/">FluentDOM</a></p></li>
<li><p><a href="http://www.pirum-project.org/">Pirum</a></p></li>
</ul>

<p>I hope that with Pirum, more Open-Source projects will start providing a PEAR
channel as a mean to install their software. If you start using Pirum for your
project, please send me an email so that I can update the list on the Pirum
website.</p>
  ]]></content></entry><entry><title type="text">The Mysteries Of Asynchronous Processing With PHP - Part 1: Asynchronous Benefits, Task Identification and Implementation Methods</title><link rel="alternate" type="text/html" href="http://blog.astrumfutura.com/archives/417-The-Mysteries-Of-Asynchronous-Processing-With-PHP-Part-1-Asynchronous-Benefits,-Task-Identification-and-Implementation-Methods.html" title="The Mysteries Of Asynchronous Processing With PHP - Part 1: Asynchronous Benefits, Task Identification and Implementation Methods"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~i19" title="Shortlink to http://blog.astrumfutura.com/archives/417-The-Mysteries-Of-Asynchronous-Processing-With-PHP-Part-1-Asynchronous-Benefits,-Task-Identification-and-Implementation-Methods.html"/><author><name>P&#xE1;draic Brady</name></author><id>http://blog.astrumfutura.com/archives/417-guid.html</id><updated>2009-09-27T14:02:00Z</updated><published>2009-09-27T14:02:00Z</published><content type="html"><![CDATA[
    Imagine a world where clients will give up on receiving responses from your application in mere seconds, where failed emails will give rise to complaints and lost business, where there exist tasks that must be performed regularly regardless of how many requests your application receives. This is not a fantasy world, it's reality. In the real world your application must be responsive, reliable and capable of recovery from errors. These are obvious needs but all too often applications fail to realise them. Sometimes, developers even fail to realise they should even be concerned about them.<br/><br/>
To offer an opening real-world example, I'll borrow from a recent discussion I had concerning the Pubsubhubbub Protocol. If you are unfamiliar with Pubsubhubbub (PuSH), it's a protocol which implements a publish-subscribe model where the publishers of RSS and Atom feeds can "push" updates to a group of Subscribers. The pushing is handled by an intermediary called a Hub which is pinged by the Publisher when they update a feed, and which then distributes the update to many Subscribers using a Callback URL they each have declared.<br/><br/>
In that discussion, the original poster was having a problem. Whenever a Hub sent his Subscriber implementation an update, it seemed to do it repetitively for some mysterious reason. Eventually, the problem was identified. The Hub implements a five second timeout. If, after five seconds, the update request was not completed because the Subscriber failed to send a valid response, it was assumed to have failed. The Hub would then attempt it again, and again, until finally its configured number of retries was used up.<br/><br/>
Why was the five second timeout being exceeded by the Subscriber? What was taking it so long in returning a response and finishing the request? You see, the Subscriber was not simply acknowledging the receipt of an update as demanded by the protocol, it was actually processing the entire update for its own use including a number of potentially expensive database operations before it completed the request. This was taking more than five seconds.<br/><br/>
Here's the problem in a nutshell. The Subscriber was performing work that had absolutely nothing to do with returning a response to the Hub and it was having an impact on the time it took to complete the request. The Hub couldn't care less about the Subscriber's processing, it was expecting a quick confirmation that the update was received. Instead, the Subscriber was effectively making it wait while it did something completely unrelated to that response. Using Asynchronous Processing, the Subscriber should have offloaded the feed processing elsewhere leaving it free to quickly respond to the Hub.<br/><h3>What is Asynchronous Processing?</h3><br/>
Asynchronous processing is a method of performing tasks outside the loop of the current request. Basically, you offload the task to another process, leaving the process serving the request free to respond quickly and without delay. Of course, not all tasks are caused by a request. Some can performed without a request trigger, like some forms of maintenance or log parsing.<br/><br/>
Implementing asynchronous processing can take a few directions:<br/><br/>
1. A parent process can spawn a child process to complete a task in the background allowing the parent process continue uninterrupted.<br/>
2. You could add tasks to a Job Queue (or even Message Queue) relying on a background daemon or scheduled process to perform batch processing of outstanding tasks in the queue.<br/>
3. You could simply have a scheduled standalone task without the queue, and which is performed regardless of what  requests are received.<br/><br/>
There are, I'm sure, many more variations. Most readers will recognise at least one of these (hint: cron <img src="http://blog.astrumfutura.com/templates/default/img/emoticons/wink.png" alt=";-)" style="display: inline; vertical-align: bottom;" class="emoticon"/>). Once you understand the nature of asynchronous processing you can find many uses for it in the most unlikely of places.<br/><h3>What Problems Does Asynchronous Processing Solve?</h3><br/>
Our example demonstrates that resource intensive tasks can be detrimental to responsiveness, so much so that it can can become detrimental in turn to the client, whether it be a machine applying a configured timeout and being forced into retrying the same request over and over, or whether it be an actual person who has to stare at a blank page as the seconds tick by.<br/><br/>
Resource intensive tasks are not the only ones worth applying asynchronous processing to, though they are likely the most obvious given their impact on clients. Most tasks worth offloading can be grouped into categories:<br/><br/>
1. Tasks which are resource intensive, i.e. needing a lot of CPU cycles or memory to complete which will add to server load and delay client responses.<br/>
2. Tasks whi<p><i>Truncated by Planet PHP, read more at <a href="http://blog.astrumfutura.com/archives/417-The-Mysteries-Of-Asynchronous-Processing-With-PHP-Part-1-Asynchronous-Benefits,-Task-Identification-and-Implementation-Methods.html">the original</a> (another 8273 bytes)</i></p>]]></content></entry><entry><title type="text">What Do You Develop On?</title><link rel="alternate" type="text/html" href="http://blog.stuartherbert.com/php/2009/09/11/what-do-you-develop-on/" title="What Do You Develop On?"/><link rel="shortlink" type="text/html" href="http://planet-php.org/~i0j" title="Shortlink to http://blog.stuartherbert.com/php/2009/09/11/what-do-you-develop-on/"/><author><name>Stuart Herbert</name></author><id>http://blog.stuartherbert.com/php/?p=156</id><updated>2009-09-11T13:25:00Z</updated><published>2009-09-11T13:25:00Z</published><content type="html"><![CDATA[<p>At work, we have quite a variety of kit that we use for development:</p>
<ol>
<li>Cheap and cheerful desktop machines w/ multiple monitors and plenty of RAM, normally with AMD CPUs. These machines mostly run some form of Linux … Ubuntu and Debian are both popular.</li>
<li>Various laptops, a fair mix of MacBook Pros and other kit running Linux.</li>
<li>Virtual machines running on the desktops and laptops, used for cross-browser testing.</li>
<li>Virtual machines running on HP servers and blades, used for system testing, release testing and production.</li>
</ol>
<p>It gives us a lot of flexibility, allows us to develop and test on standards-compliant environments (but still use Windows for testing IE), and most of the time the developer is the bottleneck not the equipment <img src='http://blog.stuartherbert.com/php/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Recently, I’ve added both a netbook and an Atom-based mini-itx machine into the mix, and this blog post is my attempt to recommend that you consider doing the same.</p>
<p>Netbooks are incredibly popular in the wider computer-owning population. Over here in the UK, they come free with many mobile broadband packages, making them cheaper than many low-end laptops. They’re sold in the supermarket and the high street. Their small form factor and relative lightweight makes them appealing to people who would never willingly cart a traditional laptop around. And they run Windows, which most people are familiar with.</p>
<p>After an initial explosion of innovation, the specs have settled around a 1.6GHz Atom processor, 1 GB of RAM and a 10″ 1024×600 resolution screen. That’s not a lot of power, and it isn’t a lot of screen estate. How do your websites look on a netbook? Does your home page or your landing pages make an impact at that size, or is your site’s message partially or completely below the fold? How do the rest of the pages look? If you’re creating an app, does the user have enough of a working area to comfortably do their tasks? Try using Google Reader or Zimbra on a netbook to see examples of what to avoid.</p>
<p>And how do your websites run on a netbook? Too much Javascript, and the pages won’t be snappy. The CPU won’t keep up, and the different latencies and throughput of mobile broadband make round-trips back to the server much more noticeable. Javascript that fires at regular intervals (e.g. rotating marketing spotlight images) can force the CPU to switch execution speeds, and so drain the netbook’s battery much quicker.</p>
<p>Testing on a netbook is one way you can spot and deal with these problems before your customers do.</p>
<p><em>Stuart is running a course in Manchester in October immediately before the PHPNW09 conference on how to setup and organise your PHP developers to ensure things run smoothly for you and your customers. <a href="http://www.methodosity.com/2009-oct/what.php">Learn more about the course</a>, or <a href="http://www.methodosity.com/2009-oct/signup.php">sign-up now</a>.</em></p>
]]></content></entry></feed>

