<?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>ant.i.am</title>
	<atom:link href="http://anthonyw.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://anthonyw.net</link>
	<description>Herpity derp???</description>
	<lastBuildDate>Thu, 12 Jan 2012 16:24:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>It has arrived!</title>
		<link>http://anthonyw.net/2012/01/it-has-arrived/</link>
		<comments>http://anthonyw.net/2012/01/it-has-arrived/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 16:24:40 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[computer hardware]]></category>
		<category><![CDATA[radeon 6850]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=318</guid>
		<description><![CDATA[I was waiting for a sale on a 6850 or a 6950 and Newegg.com had it on sale for $135 plus a $15 mail in rebate. Score!]]></description>
			<content:encoded><![CDATA[<p>I was waiting for a sale on a 6850 or a 6950 and Newegg.com had it on sale for $135 plus a $15 mail in rebate.  Score!<br />
<a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0556.jpg"><img src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0556-179x300.jpg" alt="" title="IMAG0556" width="179" height="300" class="alignleft size-medium wp-image-323" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/01/it-has-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A letter I wrote to my Senator today about PIPA/SOPA</title>
		<link>http://anthonyw.net/2012/01/a-letter-i-wrote-to-my-senator-today-about-pipasopa/</link>
		<comments>http://anthonyw.net/2012/01/a-letter-i-wrote-to-my-senator-today-about-pipasopa/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 17:52:39 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[senate sopa pipa piracy technology]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=314</guid>
		<description><![CDATA[Dear Senator, As someone who is deeply entrenched in technology (I work at a startup in Manhattan) I would know your thoughts on PIPA and the Houses proposed SOPA bill. One thing I find appalling is the lack of oversight &#8230; <a href="http://anthonyw.net/2012/01/a-letter-i-wrote-to-my-senator-today-about-pipasopa/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Dear Senator,</p>
<p>As someone who is deeply entrenched in technology (I work at a startup in Manhattan) I would know your thoughts on PIPA and the Houses proposed SOPA bill.</p>
<p>One thing I find appalling is the lack of oversight with this bill. Why did not one House representative or Senator meet with major technology companies to discuss how to tackle this issue instead of blindly charging ahead? Is this the best solution? How is it that not even the Communications, Technology and Internet subcommittee was not even consulted? I am sure anyone familiar with how DNS works would have screamed &#8220;Fus Ro Dah&#8221; (based on a game I play, anyone familiar with the internet would get the joke) at any individual who mentioned a change such as that proposed in SOPA or PIPA.</p>
<p>I know there is a lot going on in the world right now, terrorism, threats of war, Iran, etc&#8230; But the basic tenants of freedom of speech must be preserved and it will only be a matter of time before the individuals who lobbied for this power begin to abuse it. &#8220;Power tends to corrupt, and absolute power corrupts absolutely. Great men are almost always bad men.&#8221; &#8211; Lord Acton</p>
<p>I am not a proponent of online piracy or advocate it in any way but this is not the proper solution to solving the issue. If the MPAA and the RIAA spent half as much time on developing strategies to adapt to the Internet as they have lobbying for change then we wouldn&#8217;t have these very dangerous bills up for consideration.</p>
<p>I look forward to your reply,<br />
Warm Regards,<br />
Anthony Wlodarski</p>
<p>&#8212;&#8212;&#8211;<br />
I implore you exercise your first amendment rights before they are gone. I don&#8217;t know if it is the crazy in me but it seems every day, more and more, the second amendment is needed to protect the rest of them from abuse and corruption. I just wish there was a better way.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/01/a-letter-i-wrote-to-my-senator-today-about-pipasopa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a new computer is fun!</title>
		<link>http://anthonyw.net/2012/01/building-a-new-computer-is-fun/</link>
		<comments>http://anthonyw.net/2012/01/building-a-new-computer-is-fun/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 14:35:54 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[computer hardware]]></category>
		<category><![CDATA[amd]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[gigabyte]]></category>
		<category><![CDATA[intel]]></category>
		<category><![CDATA[kingston]]></category>
		<category><![CDATA[motherboard]]></category>
		<category><![CDATA[radeon]]></category>
		<category><![CDATA[ram]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=293</guid>
		<description><![CDATA[So this weekend I built a new computer. The problem with upgrading my trusty quad core Dell XPS 420 is that DDR2 at 800mhz is too damn expensive: So after scouring Newegg and local stores for many different deals that &#8230; <a href="http://anthonyw.net/2012/01/building-a-new-computer-is-fun/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So this weekend I built a new computer. The problem with upgrading my trusty quad core Dell XPS 420 is that DDR2 at 800mhz is too damn expensive:</p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/ramistoodamnhigh.jpg"><img class="alignleft size-full wp-image-295" title="ramistoodamnhigh" src="http://anthonyw.net/wp-content/uploads/2012/01/ramistoodamnhigh.jpg" alt="" width="380" height="454" /></a>So after scouring Newegg and local stores for many different deals that I slept on and hate myself for sleeping on till this day I decided to build a new machine.  The machine has to be able to handle the development tasks I throw at it as well as be able to play BF3 and Skyrim with the high and ultra settings I have been used too.  For a case I choose the venerable Antec Three Hundred.  For a motherboard I choose the Gigabyte Z68 UD3 chipset, very solid design.  For the processor I snagged a Intel i5-2500k for on the cheap which is a trust worthy CPU and can be easily over clocked.  I picked up a XFX AMD 6750 video card to hold me over till something better comes along and repurposed my existing 2TB of Sata hard drives.  All this is pulled together with 16GB of DDR3-1600 Kingston ram.  Here are some pictures of the build process that I took last night:</p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0540.jpg"><img class="alignleft size-medium wp-image-300" title="IMAG0540" src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0540-300x179.jpg" alt="" width="300" height="179" /></a></p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0541.jpg"><img class="alignleft size-medium wp-image-301" title="IMAG0541" src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0541-179x300.jpg" alt="" width="179" height="300" /></a></p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0542.jpg"><img class="alignleft size-medium wp-image-302" title="IMAG0542" src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0542-179x300.jpg" alt="" width="179" height="300" /></a></p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0543.jpg"><img class="alignleft size-medium wp-image-303" title="IMAG0543" src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0543-300x179.jpg" alt="" width="300" height="179" /></a></p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0544.jpg"><img class="alignleft size-medium wp-image-304" title="IMAG0544" src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0544-300x179.jpg" alt="" width="300" height="179" /></a></p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0547.jpg"><img class="alignleft size-medium wp-image-299" title="IMAG0547" src="http://anthonyw.net/wp-content/uploads/2012/01/IMAG0547-179x300.jpg" alt="" width="179" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/01/building-a-new-computer-is-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t use the default Solr configuration files, ever!</title>
		<link>http://anthonyw.net/2011/11/dont-use-the-default-solr-configuration-files-ever/</link>
		<comments>http://anthonyw.net/2011/11/dont-use-the-default-solr-configuration-files-ever/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 15:57:11 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Solr]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=286</guid>
		<description><![CDATA[Recently I made a mistake of raw copying the default Solr configuration files into a production environment thinking they were production ready. BIG MISTAKE! It would be due diligence to go through the default configuration and build your own configuration &#8230; <a href="http://anthonyw.net/2011/11/dont-use-the-default-solr-configuration-files-ever/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I made a mistake of raw copying the default Solr configuration files into a production environment thinking they were production ready.  BIG MISTAKE!  It would be due diligence to go through the default configuration and build your own configuration files from what you see.  Some excellent resources are on the Solr wiki.  Here are links to the <a href="http://wiki.apache.org/solr/SchemaXml">Solr schema</a>, <a href="http://wiki.apache.org/solr/SolrConfigXml">Solr configuration</a> and the <a href="http://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters">Analyzers (Filters/Tokens)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/11/dont-use-the-default-solr-configuration-files-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Authentication with Node.js and Zend Framework.</title>
		<link>http://anthonyw.net/2011/07/authentication-with-node-js-and-zend-framework/</link>
		<comments>http://anthonyw.net/2011/07/authentication-with-node-js-and-zend-framework/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 15:45:53 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=269</guid>
		<description><![CDATA[Zend Framework which is PHP based and Node.js which is JavaScript based don&#8217;t have a common connection to pass data in a bi-directional nature. I was tasked with building a bridge of sorts that would utilize existing information from Zend &#8230; <a href="http://anthonyw.net/2011/07/authentication-with-node-js-and-zend-framework/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Zend Framework which is PHP based and Node.js which is JavaScript based don&#8217;t have a common connection to pass data in a bi-directional nature.  I was tasked with building a bridge of sorts that would utilize existing information from Zend Framework with the latest release of Socket.io&#8217;s authorization mechanisms.  (If you don&#8217;t do this then arbitrary connections can happen and will be authorized.)  Lets get right into the code and see how this issue was tackled:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/** Require the http module. */</span>
<span style="color: #003366; font-weight: bold;">var</span> http <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/** Create a new http server to listen to and send requsts from. */</span>
<span style="color: #003366; font-weight: bold;">var</span> server <span style="color: #339933;">=</span> http.<span style="color: #660066;">createServer</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>req<span style="color: #339933;">,</span> res<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    res.<span style="color: #660066;">writeHead</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'Content-Type'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'text/html'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    res.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
server.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">12121</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/** Require the socket.io module */</span>
<span style="color: #003366; font-weight: bold;">var</span> io <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'socket.io'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">listen</span><span style="color: #009900;">&#40;</span>server<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/** File system library **/</span>
<span style="color: #003366; font-weight: bold;">var</span> fs <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/** Extract the session id from the headers cookies **/</span>
<span style="color: #003366; font-weight: bold;">function</span> getPHPSessionId<span style="color: #009900;">&#40;</span>cookies<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> phpSessionId <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
    cookies.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">';'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> a.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'PHPSESSID'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            phpSessionId <span style="color: #339933;">=</span> b<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> phpSessionId<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * This function will look in the PHP Session directory and look for the session
 * file.  If the file exists it will load that file as a string and then parse
 * that string for the PHP Session which will only be stored once the PHP authorization
 * method saves it.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> authorizePHPSession<span style="color: #009900;">&#40;</span>phpSessionId<span style="color: #339933;">,</span> cb<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        fs.<span style="color: #660066;">readFile</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/path/to/sessions/sess_'</span><span style="color: #339933;">+</span>phpSessionId<span style="color: #339933;">,</span> <span style="color: #3366CC;">'utf8'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>err<span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">throw</span> err<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span>phpSessionId.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
io.<span style="color: #660066;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    io.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'transports'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'xhr-polling'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'htmlfile'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'jsonp-polling'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    io.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'authorization'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> cb<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        authorizePHPSession<span style="color: #009900;">&#40;</span>getPHPSessionId<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">headers</span>.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> cb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As you can see here we have the usual Node.js lifting.  We create a http server, we create an instance of the io object from Socket.io and get to it.  However then we begin to get into the interesting functions.  &#8220;getPHPSessionId&#8221; is a utility function that will parse the cookie information attached to the handshake data.  If we find the correct cookie prefix (PHPSESSID in this instance, but this is configurable so check your php.ini file!) we extract the second part of that string as the PHP session.  If all else fails we return an empty string which will be compatible with our next function, &#8220;authorizePHPSession&#8221;.</p>
<p>&#8220;authorizePHPSession&#8221; takes two parameters, the PHP session id, and a callback function that is to be executed.  The callback must be executed as per the documentation <a href="https://github.com/LearnBoost/socket.io/wiki/Authorizing">here</a>.  This function call to read the contents of the file must be asynchronous.  Synchronous calls are dangerous in a non blocking i/o situation.  I will quote Node.js documentation:</p>
<blockquote><p>The synchronous versions will block the entire process until they complete&#8211;halting all connections.</p></blockquote>
<p>Trust me I tried the synchronous calls, I watched the connection pool halt and just stack up and it was just one mess.  Simply enough if the PHP session id exists in this file then it is authorized (how did the PHP session get into the file, well that is the next part&#8230;).  Finally pulling it all together I call:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">io.<span style="color: #660066;">configure</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    io.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'transports'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'xhr-polling'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'htmlfile'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'jsonp-polling'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    io.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'authorization'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> cb<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        authorizePHPSession<span style="color: #009900;">&#40;</span>getPHPSessionId<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">headers</span>.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> cb<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now we get into the Zend Framework portion of our example.  I am going to assume that once you have authorized the user you write some sort of information into the session.  This is our chance to insert the PHP session id to our session.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$authDbTable</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authenticate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// lets store the user in the session</span>
            <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$authDbTable</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResultRowObject</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'role'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$usersTable</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">update</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lastLogin'</span><span style="color: #339933;">=&gt;</span>date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id = ?'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">remember_me</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">checked</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		Zend_Session<span style="color: #339933;">::</span><span style="color: #004000;">rememberMe</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		Zend_Session<span style="color: #339933;">::</span><span style="color: #004000;">forgetMe</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// insert our session information.</span>
            <span style="color: #000088;">$user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">nodeAuthorization</span> <span style="color: #339933;">=</span> Zend_Session<span style="color: #339933;">::</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$auth</span> <span style="color: #339933;">=</span> Zend_Auth<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStorage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Lets discuss the semantics of this operation.  PHP is invoked by the browser request.  A cookie is written to your browser with your PHP session id.  Which is the only unique identifier which will allow you to access serialized data stored in a file on our server.  Socket.io is invoked once the page is loaded into your browser.  At this point the information contained in your cookies is passed as handshake data to our event server.  The event server does the authorization previously mentioned.  If the session string exists (which will only happen once you are authenticated) you are granted access, else you are not.</p>
<p>PHP/Node.js/Socket.io is just simply amazing!</p>
<p><strong>BIG BIG BIG EDIT</strong><br />
If the PHP garbage collector has not picked up the sessions yet as it has a random chance of running per page load you can check the stats of the file yourself.  However the one <strong>CAVEAT</strong> is that if you change the length of time for which your sessions are valid you have to do it in two places.  application.ini and or Zend_Config for PHP and in the Node.js application file variable.  Take a look at this fixed version:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * This function will look in the PHP Session directory and look for the session
 * file.  If the file exists it will load that file as a string and then parse
 * that string for the PHP Session which will only be stored once the PHP authorization
 * method saves it.  It also takes into consideration sessions that may not have been
 * gc'ed by PHP yet.
 */</span>
<span style="color: #003366; font-weight: bold;">var</span> sessionExpiration <span style="color: #339933;">=</span> <span style="color: #CC0000;">86400</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> authorizePHPSession<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> cb<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> phpSessionId <span style="color: #339933;">=</span> getPHPSessionId<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">headers</span>.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fs.<span style="color: #660066;">stat</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/var/lib/php5/sess_'</span><span style="color: #339933;">+</span>phpSessionId<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>err<span style="color: #339933;">,</span> stats<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>Date.<span style="color: #660066;">now</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #009900;">&#40;</span>Date.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>stats.<span style="color: #660066;">mtime</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> sessionExpiration<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                fs.<span style="color: #660066;">readFile</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'/var/lib/php5/sess_'</span><span style="color: #339933;">+</span>phpSessionId<span style="color: #339933;">,</span> <span style="color: #3366CC;">'utf8'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>err<span style="color: #339933;">,</span> fileContents<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">throw</span> err<span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>fileContents.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span>phpSessionId.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        data.<span style="color: #660066;">phpSessionId</span> <span style="color: #339933;">=</span> phpSessionId.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                cb<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>            
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This was brought to my attention by Trii chilling out in #phpc on irc.freenode.org.  You can visit him here at <a href="http://gplus.to/joshj">g+</a></p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/07/authentication-with-node-js-and-zend-framework/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nifty little overlay plugin I wrote in JavaScript as a jQuery plugin.</title>
		<link>http://anthonyw.net/2011/07/nifty-little-overlay-plugin-i-wrote-in-javascript-as-a-jquery-plugin/</link>
		<comments>http://anthonyw.net/2011/07/nifty-little-overlay-plugin-i-wrote-in-javascript-as-a-jquery-plugin/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 00:21:35 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=262</guid>
		<description><![CDATA[So I analyzed what was behind Flowplayer&#8217;s overlay plugin and decided that if I didn&#8217;t want to rehaul my entire sites structure to adhere to their wants and needs I would have to write my own. So I did, you &#8230; <a href="http://anthonyw.net/2011/07/nifty-little-overlay-plugin-i-wrote-in-javascript-as-a-jquery-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I analyzed what was behind Flowplayer&#8217;s overlay plugin and decided that if I didn&#8217;t want to rehaul my entire sites structure to adhere to their wants and needs I would have to write my own.  So I did, you can check it out at <a href="http://www.overlay.anthonyw.net">http://www.overlay.anthonyw.net</a>.  If you wish to download the plugin, it has been provided with the MIT license so feel free to modify as necessary.  Soon it will make its way onto github.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/07/nifty-little-overlay-plugin-i-wrote-in-javascript-as-a-jquery-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When someone tells you to read the source in Zend Framework, there is a reason.</title>
		<link>http://anthonyw.net/2011/06/when-someone-tells-you-to-read-the-source-in-zend-framework-there-is-a-reason/</link>
		<comments>http://anthonyw.net/2011/06/when-someone-tells-you-to-read-the-source-in-zend-framework-there-is-a-reason/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 13:44:32 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=250</guid>
		<description><![CDATA[Zend Framework (a.k.a. ZF) is the swiss army knife of MVC based frameworks. (The discussion of ZF really being a framework versus a loosely coupled library is another discussion in its own.) Name one thing you want to do with &#8230; <a href="http://anthonyw.net/2011/06/when-someone-tells-you-to-read-the-source-in-zend-framework-there-is-a-reason/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="Zend Framework" href="http://framework.zend.com/" target="_blank">Zend Framework</a> (a.k.a. ZF) is the swiss army knife of MVC based frameworks.  (The discussion of ZF really being a framework versus a loosely coupled library is another discussion in its own.)  Name one thing you want to do with a framework and chances are ZF already supports it out of the box and if not that is okay too, it is easily extend-able (for some reasons my blog doesn&#8217;t like intransitive verbs so pardon the hyphen).  However learning how to wield ZF can seem like a daunting task.  One thing I learned early on with ZF was that the curators and associates in the ZF ecosystem always fall back to the root of &#8220;read the code/api/documentation&#8221;.  With good reason too!  It is not the volunteers simply shrugging you off but it is for your own good.  Lets take for example the use of the class <em>Zend_Validate_File_ImageSize</em>.  If you haven&#8217;t ever used this class before a quick reading into the class name tells you it validates a file and if that file is an image, the image size.  Fair enough but how do we use this class?  Well I use Netbeans and the easiest way for me to open a file is to CTRL+click the class name, Netbeans does a wonderful job of bringing you right to the constructor for the class.</p>
<p>Now we are presented with:</p>
<style type="text/css">
.wp_syntax pre { font-size: 10px !important; }
</style>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #009933; font-style: italic;">/**
     * Sets validator options
     *
     * Accepts the following option keys:
     * - minheight
     * - minwidth
     * - maxheight
     * - maxwidth
     *
     * @param  Zend_Config|array $options
     * @return void
     */</span>
    <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;">$options</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> instanceof Zend_Config<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">func_num_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'minwidth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$argv</span> <span style="color: #339933;">=</span> <span style="color: #990000;">func_get_args</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'minheight'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'maxwidth'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'maxheight'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$argv</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Validate/Exception.php'</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_Exception <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid options to validator provided'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'minheight'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'minwidth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">setImageMin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'maxheight'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'maxwidth'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</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;">setImageMax</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Reading over this we can see that the constructor accepts a few different types of options.  It will accept a single Zend_Config class instance, a string defining the minimum width of the image, or an array defining some or all of the options that can be set.  Which options can be set?  Well the ones that the code says we can use: minwidth, minheight, maxwidth, maxheight (In this order too!).  I personally find using Zend_Config overkill so we could invoke the instance like so</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//backwards compatibility supports this but I find this to be something that should be broke as the constructors are now unified and this could be messy</span>
<span style="color: #000088;">$validatorA</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_File_Image_Size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">110</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// suggested way of passing in parameters to the constructor</span>
<span style="color: #000088;">$validatorB</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Validate_File_Image_Size<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'minheight'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'minwidth'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'maxheight'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">110</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'maxwidth'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">110</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Well that&#8217;s it, this technique can be used for any class in Zend Framework.  ZF is flexible enough to allow you to choose how you want to build your projects (within reason).  Always RTFM before asking questions, sometimes reading and finding the answer is faster than asking and waiting for the answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/06/when-someone-tells-you-to-read-the-source-in-zend-framework-there-is-a-reason/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If anyone is looking for information on how to build debian packages, this PDF will help.</title>
		<link>http://anthonyw.net/2011/05/if-anyone-is-looking-for-information-on-how-to-build-debian-packages-this-pdf-will-help/</link>
		<comments>http://anthonyw.net/2011/05/if-anyone-is-looking-for-information-on-how-to-build-debian-packages-this-pdf-will-help/#comments</comments>
		<pubDate>Thu, 19 May 2011 15:37:04 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[debian dpkg deb source build]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=240</guid>
		<description><![CDATA[Taken from: http://forums.debian.net/viewtopic.php?p=228570. Build-Pkg-Smart-Way]]></description>
			<content:encoded><![CDATA[<p>Taken from: <a href="http://forums.debian.net/viewtopic.php?p=228570" target="_blank">http://forums.debian.net/viewtopic.php?p=228570</a>.<br />
<a href='http://anthonyw.net/wp-content/uploads/2011/05/Build-Pkg-Smart-Way.pdf'>Build-Pkg-Smart-Way</a></p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/05/if-anyone-is-looking-for-information-on-how-to-build-debian-packages-this-pdf-will-help/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The when and where of pulling data from the database.</title>
		<link>http://anthonyw.net/2011/05/the-when-and-where-of-pulling-data-from-the-database/</link>
		<comments>http://anthonyw.net/2011/05/the-when-and-where-of-pulling-data-from-the-database/#comments</comments>
		<pubDate>Tue, 17 May 2011 13:46:56 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=230</guid>
		<description><![CDATA[If you work on an application (web/desktop, etc&#8230;) where in the program logic do you pull information about the current user? This is a question I have toiled with constantly for a few months now. Being a little bit wishy &#8230; <a href="http://anthonyw.net/2011/05/the-when-and-where-of-pulling-data-from-the-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you work on an application (web/desktop, etc&#8230;) where in the program logic do you pull information about the current user?  This is a question I have toiled with constantly for a few months now.  Being a little bit wishy washy on the subject there are two trains of thoughts here, option A and option B.  Option A is pulling the information from the database as soon as the application wakes up.  Option B is pulling pieces of the current user as necessary.  Option A has the following benefits.  All information can be pulled at once and in one location in the code.  This means that if you were to check the data in the registry/view it would already be set as a mechanism in your plug-in or bootstrapping process would have loaded it for you.  However if you have made changes to the user after this loading period then you would incur another loading period as the data would be stale.  If this was a website you could quite possibly get away with displaying stale data at first and then modifiers update the presentation layer via ajax.  Option B involves you loading only what is necessary where you need it (other than in the view if you are in the MVC state of mind).  For example in one part of your controller you need the users user name and email address, then a few lines down you need their data of birth and the time that their profile was modified.  Each query would load only what is necessary at that time.  This presents a problem though you have fragmented and small queries in addition to having more queries than Option A.  However this presents you with fresh data in every instant as you are pulling it as close to presentation as possible.  I am on the fence about both methods but did some brain storming on paper and created a few scribbles.</p>
<p>Both options are viable but it depends on the situation.</p>
<div id="attachment_232" class="wp-caption alignleft" style="width: 239px"><a href="http://anthonyw.net/wp-content/uploads/2011/05/05161100.jpg"><img src="http://anthonyw.net/wp-content/uploads/2011/05/05161100-229x300.jpg" alt="Pulling data diagram." title="Pulling data diagram" width="229" height="300" class="size-medium wp-image-232" /></a><p class="wp-caption-text">Pulling data diagram.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/05/the-when-and-where-of-pulling-data-from-the-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing Jetty and Solr with PHP authentication.</title>
		<link>http://anthonyw.net/2011/04/securing-jetty-and-solr-with-php-authentication/</link>
		<comments>http://anthonyw.net/2011/04/securing-jetty-and-solr-with-php-authentication/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 23:40:05 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Jetty]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Solr]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=202</guid>
		<description><![CDATA[If you ever have set up Solr in a production environment you have probably wondered how to secure it. Jetty is the container that comes default with most Solr nightly builds and does just fine in a production environment with &#8230; <a href="http://anthonyw.net/2011/04/securing-jetty-and-solr-with-php-authentication/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you ever have set up Solr in a production environment you have probably wondered how to secure it.  Jetty is the container that comes default with most Solr nightly builds and does just fine in a production environment with a few tweaks.  The focus of this post is to first introduce you to a simple setup that will allow you to setup BASIC http authentication with Jetty and in the second part of this post will show you how to extend &#8220;Apache_Solr_HttpTransport_Abstract&#8221; which is an abstract class from the Solr-Php-Client project found here:<a href="http://code.google.com/p/solr-php-client/"> http://code.google.com/p/solr-php-client/</a>.  Lets get on with setting up Jetty to be secure.  First lets establish the installation path of Jetty as JETTY_HOME, for example I have a Solr installation installed at &#8220;/opt/solr/solr-production&#8221;.  For all intents and purposes this is Jetty&#8217;s home.  So when I refer to JETTY_HOME, I am referring to the home directory of Jetty.  Within JETTY_HOME is a folder called &#8220;/etc&#8221;, inside of this folder you will find jetty.xml and webdefault.xml.  Crank open these two files in your favorite editor (I used VI).  Inside of webdefault.xml right before the closing &#8220;&lt;/web-app&gt;&#8221; tag place the following:</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;security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Solr authenticated application<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>administrator<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;login-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>BASIC<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-method<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;realm-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Solr<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/realm-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/login-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The previous configuration strings set up a few things, these are the url pattern (&#8220;/&#8221; means the entire application), the role (which is &#8220;administrator&#8221;), the authentication method (BASIC) and the realm under which we will be authenticating our users.  Please visit <a href="http://docs.codehaus.org/display/JETTY/Realms">http://docs.codehaus.org/display/JETTY/Realms</a> for detailed information in regards to securing Jetty.  Now we move onto jetty.xml inside the &#8220;JETTY_HOME/etc&#8221; directory.  Inside of this file do a search for &#8220;UserRealms&#8221;  chances are the configuration for authentication realms is just commented out, if not add the following:</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;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;UserRealms&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Array</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;org.mortbay.jetty.security.UserRealm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;New</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.mortbay.jetty.security.HashUserRealm&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>My Solr<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;config&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;SystemProperty</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jetty.home&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>/etc/realm.properties<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Set</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;refreshInterval&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/New<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Set<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>This basically tells Jetty where the file for user names and passwords.  Which would be &#8220;JETTY_HOME/etc/realm.properties&#8221;.  Chances are this file does not exist already, it is okay to create the file (sudo touch realm.properties in the JETTY_HOME/etc folder).  This file has a format that must be adhered to, but before that lets generate a password for the &#8220;administrator&#8221; user.  I like to execute the following:</p>
<pre>
$ echo -n "test" | openssl md5
098f6bcd4621d373cade4e832627b4f6
</pre>
<p>(BTW &#8220;test&#8221; is a poor password, please don&#8217;t copy this verbatim.)</p>
<p>So with that password we are ready to put an entry in the realm.properties file.  As per the Jetty documents the format is &#8220;username: password[,rolename ...]&#8220;, where:</p>
<ul>
<li>username is the user&#8217;s unique identity</li>
<li>password is the user&#8217;s (possibly obfuscated or MD5 encrypted) password</li>
<li> rolename is the user&#8217;s role</li>
</ul>
<p>So for example:</p>
<pre>
administrator: MD5:098f6bcd4621d373cade4e832627b4f6,administrator
</pre>
<p>would work just fine.  There you go, you have secured Jetty to an extent.  A word of precaution.  CHMOD that file to 600 as soon as it is created, you will sleep better at night.  Also CHOWN it to root:root as well.  Restart your Solr package and then visit your Solr instance in the browser, you will be prompted for a user name and password for the realm.  Now we can move onto making sure our PHP requests are honored with the right authentication information.</p>
<p>The solr-php-client project is coded in the Zend Framework API style of coding.  It makes sense and it integrated very easily into my company&#8217;s ZF application, I am sure the process would be similar for other Solr PHP clients but this one will focus purely on this project.  If you use the Apache_Solr_Service class you will notice that by default it uses a FileGetContents http transport.  This class is found in  &#8220;/Apache/Solr/HttpTransport/FileGetContents.php&#8221; of the solr client download.  So this class at first glance looks to be extend-able but since the author decided to make the stream contexts private you cannot access them in a child class.  Instead I decided to extend the http transport abstract class found in &#8220;/Apache/Solr/HttpTransport/Abstract.php&#8221;.  This allows me to pull the best parts of the FileGetContents.php file and merge them with http headers to authenticate with.  Here is the class in its entirety:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Get2KnowMe_Search_FileGetContents <span style="color: #000000; font-weight: bold;">extends</span> Apache_Solr_HttpTransport_Abstract <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$authorization</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_getContext</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_postContext</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_headContext</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;">$authorization</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</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;">authorization</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$authorization</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$username</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getContext <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postContext <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headContext <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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> performGetRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authorization</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Authorization: Basic '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// set the timeout if specified</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeout</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">&gt;</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// timeouts with file_get_contents seem to need</span>
                <span style="color: #666666; font-style: italic;">// to be halved to work as expected</span>
                <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timeout'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// use the default timeout pulled from default_socket_timeout otherwise</span>
                <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timeout'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDefaultTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// $http_response_headers will be updated by the call to file_get_contents later</span>
        <span style="color: #666666; font-style: italic;">// see http://us.php.net/manual/en/wrappers.http.php for documentation</span>
        <span style="color: #666666; font-style: italic;">// Unfortunately, it will still create a notice in analyzers if we don't set it here</span>
        <span style="color: #000088;">$http_response_header</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$responseBody</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getResponseFromParts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseBody</span><span style="color: #339933;">,</span> <span style="color: #000088;">$http_response_header</span><span style="color: #009900;">&#41;</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> performHeadRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authorization</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Authorization: Basic '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headContext<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'http'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                                <span style="color: #666666; font-style: italic;">// set HTTP method</span>
                                <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'HEAD'</span><span style="color: #339933;">,</span>
&nbsp;
                                <span style="color: #666666; font-style: italic;">// default timeout</span>
                                <span style="color: #0000ff;">'timeout'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDefaultTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// set the timeout if specified</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeout</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">&gt;</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// timeouts with file_get_contents seem to need</span>
                <span style="color: #666666; font-style: italic;">// to be halved to work as expected</span>
                <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timeout'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// $http_response_headers will be updated by the call to file_get_contents later</span>
        <span style="color: #666666; font-style: italic;">// see http://us.php.net/manual/en/wrappers.http.php for documentation</span>
        <span style="color: #666666; font-style: italic;">// Unfortunately, it will still create a notice in analyzers if we don't set it here</span>
        <span style="color: #000088;">$http_response_header</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$responseBody</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getResponseFromParts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseBody</span><span style="color: #339933;">,</span> <span style="color: #000088;">$http_response_header</span><span style="color: #009900;">&#41;</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> performPostRequest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rawPost</span><span style="color: #339933;">,</span> <span style="color: #000088;">$contentType</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">authorization</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'header'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Authorization: Basic '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postContext<span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'http'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                                <span style="color: #666666; font-style: italic;">// set HTTP method</span>
                                <span style="color: #0000ff;">'method'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
&nbsp;
                                <span style="color: #666666; font-style: italic;">// Add our posted content type</span>
                                <span style="color: #0000ff;">'header'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Content-Type: <span style="color: #006699; font-weight: bold;">$contentType</span>&quot;</span><span style="color: #339933;">,</span>
&nbsp;
                                <span style="color: #666666; font-style: italic;">// the posted content</span>
                                <span style="color: #0000ff;">'content'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$rawPost</span><span style="color: #339933;">,</span>
&nbsp;
                                <span style="color: #666666; font-style: italic;">// default timeout</span>
                                <span style="color: #0000ff;">'timeout'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDefaultTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// set the timeout if specified</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$timeout</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">FALSE</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">&gt;</span> <span style="color:#800080;">0.0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// timeouts with file_get_contents seem to need</span>
                <span style="color: #666666; font-style: italic;">// to be halved to work as expected</span>
                <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$timeout</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'timeout'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// $http_response_header will be updated by the call to file_get_contents later</span>
        <span style="color: #666666; font-style: italic;">// see http://us.php.net/manual/en/wrappers.http.php for documentation</span>
        <span style="color: #666666; font-style: italic;">// Unfortunately, it will still create a notice in analyzers if we don't set it here</span>
        <span style="color: #000088;">$http_response_header</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$responseBody</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// reset content of post context to reclaim memory</span>
        <span style="color: #990000;">stream_context_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_postContext<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getResponseFromParts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$responseBody</span><span style="color: #339933;">,</span> <span style="color: #000088;">$http_response_header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _getResponseFromParts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$rawResponse</span><span style="color: #339933;">,</span> <span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Assume 0, false as defaults</span>
            <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$contentType</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">//iterate through headers for real status, type, and encoding</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                    <span style="color: #666666; font-style: italic;">//look at the first headers for the HTTP status code</span>
                    <span style="color: #666666; font-style: italic;">//and message (errors are usually returned this way)</span>
                    <span style="color: #666666; font-style: italic;">//</span>
                    <span style="color: #666666; font-style: italic;">//HTTP 100 Continue response can also be returned before</span>
                    <span style="color: #666666; font-style: italic;">//the REAL status header, so we need look until we find</span>
                    <span style="color: #666666; font-style: italic;">//the last header starting with HTTP</span>
                    <span style="color: #666666; font-style: italic;">//</span>
                    <span style="color: #666666; font-style: italic;">//the spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1</span>
                    <span style="color: #666666; font-style: italic;">//</span>
                    <span style="color: #666666; font-style: italic;">//Thanks to Daniel Andersson for pointing out this oversight</span>
                    <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'HTTP'</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                            <span style="color: #666666; font-style: italic;">// we can do a intval on status line without the &quot;HTTP/1.X &quot; to get the code</span>
                            <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                            <span style="color: #666666; font-style: italic;">// remove this from the headers so we can check for more</span>
                            <span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
&nbsp;
                    <span style="color: #666666; font-style: italic;">//Look for the Content-Type response header and determine type</span>
                    <span style="color: #666666; font-style: italic;">//and encoding from it (if possible - such as 'Content-Type: text/plain; charset=UTF-8')</span>
                    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpHeaders</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                            <span style="color: #666666; font-style: italic;">// look for the header that starts appropriately</span>
                            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strncasecmp</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$header</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Content-Type:'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
                            <span style="color: #009900;">&#123;</span>
                                    <span style="color: #000088;">$contentType</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$header</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">13</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                    <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Apache_Solr_HttpTransport_Response<span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #339933;">,</span> <span style="color: #000088;">$contentType</span><span style="color: #339933;">,</span> <span style="color: #000088;">$rawResponse</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>    
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>SOLR_USERNAME and SOLR_PASSWORD are part of configurations that are set before the calls are made from a configuration file.  It was really easy to get the ball rolling and Jetty is an excellent choice as a Solr container.  If you have any questions, comments, concerns or tips to make Solr even more secure don&#8217;t hesitate to post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2011/04/securing-jetty-and-solr-with-php-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

