<?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>Wed, 21 Mar 2012 18:27:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using jQuery to make your site more appealing.</title>
		<link>http://anthonyw.net/2012/03/using-jquery-to-make-your-site-more-appealing/</link>
		<comments>http://anthonyw.net/2012/03/using-jquery-to-make-your-site-more-appealing/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 18:27:27 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=381</guid>
		<description><![CDATA[On http://www.get2know.me we test every now and again the barrier for entry onto our site. At first our forms were clunky, required users to type their date of birth in manually and we would make sense of it using PHP&#8217;s &#8230; <a href="http://anthonyw.net/2012/03/using-jquery-to-make-your-site-more-appealing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On <a href="http://www.get2know.me" title="Get2Know.me" target="_blank">http://www.get2know.me</a> we test every now and again the barrier for entry onto our site.  At first our forms were clunky, required users to type their date of birth in manually and we would make sense of it using PHP&#8217;s strtotime() function and then we would validate it after that.  Next we modified the date form to have a specific format &#8216;mm/dd/yyyy&#8217; which was checked by a custom validation class, then Zend Framework&#8217;s default date validation class after a reworking.  Finally I sat down and began pondering what would be the easiest way for a user to get onto our site and if I can apply that principle to one or more fields on our forms, there has to be a better way&#8230;  The answer, jQuery.  jQuery has slew of UI widgets available in their UI library that we have skinned and use repeatedly on the site.  Instead of clunky drop downs or text areas that require some weird format we now have the Datepicker widget beautifully themed and it restricts the age of the person signing up with the service to match our TOS (still validated on the back end <img src='http://anthonyw.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).  Secondly we have a zip code field on our form which if anyone has had to manage locations knows that this could be a PITA.  Using jQuery&#8217;s auto complete functionality I now have users locked into our geolocation information with a nicely formated dropped down menu.  Take a look at the images below demonstrating how forms should be built.</p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/03/birthday.jpg"><img src="http://anthonyw.net/wp-content/uploads/2012/03/birthday-300x269.jpg" alt="" title="birthday" width="300" height="269" class="aligncenter size-medium wp-image-382" /></a></p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/03/location.jpg"><img src="http://anthonyw.net/wp-content/uploads/2012/03/location.jpg" alt="" title="location" width="273" height="242" class="aligncenter size-full wp-image-383" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/03/using-jquery-to-make-your-site-more-appealing/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Scroll detection in browsers</title>
		<link>http://anthonyw.net/2012/03/scroll-detection-in-browsers/</link>
		<comments>http://anthonyw.net/2012/03/scroll-detection-in-browsers/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 13:05:03 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[html5]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=365</guid>
		<description><![CDATA[The problem: Design a set of JavaScript functions that will work across browsers which will enable a form submit button after a element containing legal text has been fully read, i.e. scrolled to the bottom. The solution: &#60;script type=&#34;text/javascript&#34;&#62; $(function() &#8230; <a href="http://anthonyw.net/2012/03/scroll-detection-in-browsers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The problem:  Design a set of JavaScript functions that will work across browsers which will enable a form submit button after a element containing legal text has been fully read, i.e. scrolled to the bottom.</p>
<p>The solution:</p>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
		$(function() {
		$(&#39;#long-text&#39;).scroll(function(e) {
			if(($(e.target).height() + e.target.scrollTop) == e.target.scrollHeight) {
				$(&#39;#submit&#39;).attr(&#39;disabled&#39;, false);
			}
		});
	});
&lt;/script&gt;
</pre>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/03/enable-submit.html">Here is a working demonstration.</a>  This assumes that you utilize the jQuery library, otherwise there is not really a simple solution to detect scrolling at the DOM level.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/03/scroll-detection-in-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Node.js and Zend Auth with Sessions stored in the database.</title>
		<link>http://anthonyw.net/2012/03/node-js-and-zend-auth-with-sessions-stored-in-the-database/</link>
		<comments>http://anthonyw.net/2012/03/node-js-and-zend-auth-with-sessions-stored-in-the-database/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 18:56:44 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=356</guid>
		<description><![CDATA[Recently on a project I had to make changes to a underlying portion of the sites architecture to move sessions in Zend Framework from file storage to database storage. However this affected a piece of the architecture. Node.js, which manages &#8230; <a href="http://anthonyw.net/2012/03/node-js-and-zend-auth-with-sessions-stored-in-the-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently on a project I had to make changes to a underlying portion of the sites architecture to move sessions in Zend Framework from file storage to database storage.  However this affected a piece of the architecture.  Node.js, which manages all our real time interaction, looked at sessions at the file level.  This was quite a easy transition for the function as it was abstracted away in a function call so the theory was to just replace the function &#8220;guts&#8221; with a new component.  In regards to setting up Node.js authentication with Zend Framework please check out <a href="http://anthonyw.net/2011/07/authentication-with-node-js-and-zend-framework/" title="Authentication with Node.js and Zend Framework." target="_blank">this</a> (http://anthonyw.net/?p=269) article.</p>
<p>The original function:</p>
<pre>
function authorizePHPSession(phpSessionId, cb) {
    try {
        fs.readFile('/path/to/sessions/sess_'+phpSessionId, 'utf8', function(err, data) {
            if(err) {
                throw err;
            }

            if(data.search(phpSessionId.toString()) > -1) {
                cb(null, true);
            } else {
                cb(null, false);
            }
        });
    } catch(e) {
        cb(null, false);
    }
}
</pre>
<p>Here is the new code:</p>
<pre>
function authorizePHPSession(data, cb) {
    var phpSessionId = getPHPSessionId(data.headers.cookie);
    dbClient.connect();
    dbClient.query(
        "SELECT * FROM `Sessions` WHERE data LIKE '%Zend_Auth|a:1:{s:7:\"storage\";s:%:\"%\";}%' AND `id` = ?",
        [phpSessionId],
        function(error, rows, fields) {
            if(error) {
                console.log('Error: ' +error);
                cb(null, false);
            } else {
                if(rows.length == 1) {
                    data.phpSessionId = phpSessionId.toString();
                    cb(null, true);
                } else {
                    cb(null, false);
                }
            }
        });
    dbClient.end();
}
</pre>
<p>This authorization check now access the Sessions table set up via Zend Framework, for more information in regards to moving session from the file level to the database level please check out this article: <a href="http://dionysus.uraganov.net/frameworks/zend-framework-storing-session-in-database/" title="Zend Framework: Storing Session in Database" target="_blank">http://dionysus.uraganov.net/frameworks/zend-framework-storing-session-in-database/</a>.  The check makes two assumptions.  One there is an &#8220;id&#8221; field in your table schema that matches the string in your headers/cookies.  Second is the string it matches againnst the database entries.  The web application uses the default Zend_Auth namespace so if there are customizations on this namespace the string will vary based on that customization.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/03/node-js-and-zend-auth-with-sessions-stored-in-the-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How I stumbled upon a Dodge Charger with the Blacktop package.</title>
		<link>http://anthonyw.net/2012/02/how-i-stumbled-upon-a-dodge-charger-with-the-blacktop-package/</link>
		<comments>http://anthonyw.net/2012/02/how-i-stumbled-upon-a-dodge-charger-with-the-blacktop-package/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 19:02:45 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[cars]]></category>
		<category><![CDATA[car]]></category>
		<category><![CDATA[dodge]]></category>
		<category><![CDATA[love]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=350</guid>
		<description><![CDATA[So to give a little history on this subject. I once owned a Dodge. Best car I ever had, fun, easy to customize, just a PITA when things went wrong. Modified it so much that it was not street legal &#8230; <a href="http://anthonyw.net/2012/02/how-i-stumbled-upon-a-dodge-charger-with-the-blacktop-package/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So to give a little history on this subject.  I once owned a Dodge.  Best car I ever had, fun, easy to customize, just a PITA when things went wrong.  Modified it so much that it was not street legal and or driveable except on a very long stretch of road far off in Germany&#8230;  Enter the Acura RSX I currently own.  Hell of a reliable and powerful car.  I am grateful that it gets me to the super market reliable and fast when I get on the gas, but I have had enough.  I want something bigger, able to fit my friends in it and it has to above else look mean as hell.</p>
<p>One day while driving along a high way in Jersey City I passed the Hudson Dodge dealership.  Something out of the ordinary caught my eye.  Silver Charger with really big black rims&#8230;  I pulled over into the visitor parking area and instantly fell in love.  This car was immaculate.  I mean it has everything found in the higher end V8 models and then some.  A ridiculously loud sound system, huge wheels, the new 3.6L V6, and the new ZF 8-speed transmission.  This new transmissions allows this car to have more bark than its bite.  I spoke with the salesman briefly and asked about the sticker price, how much I can expect for a trade in with my Acura, and when I can test drive it.</p>
<p>I still have yet to test drive it due to time constraints but I did get a chance to sit in it and play with the interior.  It is a step above anything I own and I look forward to getting one by the end of the year.  Here is a quick picture that I snapped as I left the dealership.</p>
<p><a href="http://anthonyw.net/wp-content/uploads/2012/02/IMAG0616.jpg"><img src="http://anthonyw.net/wp-content/uploads/2012/02/IMAG0616-1024x612.jpg" alt="" title="IMAG0616" width="584" height="349" class="alignleft size-large wp-image-351" /></a></p>
<p>This car is beautiful, I am in love again with a Dodge.</p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/02/how-i-stumbled-upon-a-dodge-charger-with-the-blacktop-package/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Data Mapper pattern, it&#8217;s pretty good.  Here&#8217;s why.</title>
		<link>http://anthonyw.net/2012/02/the-data-mapper-pattern-its-pretty-good-heres-why/</link>
		<comments>http://anthonyw.net/2012/02/the-data-mapper-pattern-its-pretty-good-heres-why/#comments</comments>
		<pubDate>Tue, 28 Feb 2012 05:00:30 +0000</pubDate>
		<dc:creator>anthony</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://anthonyw.net/?p=328</guid>
		<description><![CDATA[Recenly I was doing a project utilizing Zend Framework and I came to a fork in the road. One path was to build my own ORM persistence layer akin to Doctrine or utilize the Data Mapper pattern. Since I don&#8217;t &#8230; <a href="http://anthonyw.net/2012/02/the-data-mapper-pattern-its-pretty-good-heres-why/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recenly I was doing a project utilizing Zend Framework and I came to a fork in the road.  One path was to build my own ORM persistence layer akin to Doctrine or utilize the Data Mapper pattern.  Since I don&#8217;t like reinventing the wheel but I feel that Doctrine still doesn&#8217;t integrate as well with Zend Framework 1.X (Bisna is great but since there are a lot of issues with Namespaces and lazy loading it is a PITA to get running) I decided to follow the route of working with the Data Mapper pattern.  If you want to research what the Data Mapper pattern is I suggest you visit http://martinfowler.com/eaaCatalog/dataMapper.html and take a look at what the pattern entails.</p>
<p>Lets say that you have three different database tables Users, Diets and Pets.  These three tables represent objects that you can manipulate in your code, however there is no quick or easy method to deliver the boilerplate for these &#8220;models&#8221;.  Given enough thought I came up with a base class and it looks something like this:</p>
<p><code></p>
<pre style="font-size:10px;">
&lt;?php
class Model {
    protected $_data = array();

    public function __get($name) {
        if(isset($this-&gt;_data[$name])) {
            return $this-&gt;_data[$name];
        }

        return null;
    }

    public function __set($name, $value) {
        $this-&gt;_data[$name] = $value;
    }

    public function toArray() {
        return $this-&gt;_data;
    }
}
?&gt;
</pre>
<p></code></p>
<p>Seems pretty simple, fair enough.  This code however goes a long way.  Since the main data store in the class &#8220;_data&#8221; is kept protected we have no other way to access properties except the magic __get/__set methods.  This can either be a blessing or a nightmare.  If you do not have an IDE such as Netbeans or PhpStorm using annotations will not help you however if you do, then you are ahead of the game.  Since this class is meant to be extended adding annotations to the base class is meaningless, however for the Pets class lets say it looks something like this:</p>
<p><code></p>
<pre style="font-size:10px;">
&lt;?php
/**
 * @property $user_id
 * @property $pet
 * @property $favorite
 */
class Application_Model_Pet extends Model {

}
?&gt;
</pre>
<p></code></p>
<p>The annotations serve a dual purpose: 1.) If anyone looks at the source for this model they will know exactly how it works, 2.) If anyone has a ide capable of reading annotations you can rest assured that when you are working with the specified model you will be able to use code completion to the maximum (helps out when you are working with 300 models and forget exactly what property is a member of what class&#8230;).  Now the second part of using the Data Mapper pattern is building a mapper class that will feed the data into the class as well as send it back to the database when you want to save it.  This is pretty trivial if you are working with Zend Framework.  Here is an example mapper class.</p>
<p><code></p>
<pre style="font-size:10px;">
&lt;?php
class Application_Model_PetMapper {
    protected $dbTable;
    private $ignoreProperties = array();

    public function setDbTable($dbTable) {
        if(is_string($dbTable)) {
            $dbTable = new $dbTable();
        }

        if(!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception(&#39;Invalid table data gateway provided.&#39;);
        }

        $this-&gt;dbTable = $dbTable;
        return $this;
    }

    /**
     * @return Application_Model_DbTable_DietaryRestrictions
     */
    public function getDbTable() {
        if($this-&gt;dbTable === null) {
            $this-&gt;setDbTable(&#39;Application_Model_DbTable_Pets&#39;);
        }

        return $this-&gt;dbTable;
    }

    /**
     * @param $user_id
     * @param $pet
     * @return Application_Model_Pet|null
     */
    public function find($user_id,$pet) {
        $result = $this-&gt;getDbTable()-&gt;find($user_id, $pet);
        if(count($result) == 0) {
            return null;
        }
        $row = $result-&gt;current();
        $p = new Application_Model_Pet();
        foreach($row-&gt;toArray() as $k=&gt;$v) {
            $p-&gt;$k = $v;
        }
        return $p;
    }

    /**
     * @param $column
     * @param $value
     * @return array|null
     */
    public function findBy($column, $value) {
        $result = $this-&gt;getDbTable()-&gt;fetchAll(array(&quot;$column = ?&quot;=&gt;$value));
        if(count($result) === 0) {
            return null;
        }

        $collection = array();
        foreach($result as $v) {
            $p = new Application_Model_Pet();
            $e = $v-&gt;toArray();
            foreach($e as $k=&gt;$value) {
                $p-&gt;$k = $value;
            }
            $collection[] = $p;
        }
        return $collection;
    }

    public function save(Application_Model_Pet $p) {
        $data = $p-&gt;toArray();

        foreach($this-&gt;ignoreProperties as $property) {
            if(isset($data[$property])) {
                unset($data[$property]);
            }
        }

        $db = $this-&gt;getDbTable()-&gt;getAdapter();
        $sql = &#39;INSERT INTO
                        `Pets` (`user_id`, `pet`, `favorite`)
                    VALUES
                        (?,?,?)
                    ON DUPLICATE KEY UPDATE
                        `user_id`=`user_id`, `pet`=`pet`, `favorite`=&#39;.(int)$data[&#39;favorite&#39;];
        $result = $db-&gt;query($sql, array((int)$data[&#39;user_id&#39;], (int)$data[&#39;pet&#39;], (int)$data[&#39;favorite&#39;]));
        return (bool)$result-&gt;rowCount();
    }

    public function delete(Application_Model_Pet $p) {
        if($p-&gt;user_id !== null &amp;&amp; $p-&gt;pet !== null) {
            return (bool)$this-&gt;getDbTable()-&gt;delete(array(&#39;user_id = ?&#39;=&gt;(int)$p-&gt;user_id, &#39;pet = ?&#39;=&gt;(int)$p-&gt;pet));
        }

        return false;
    }
}
?&gt;
</pre>
<p></code></p>
<p>Given enough time you can abstract away the mapper class and only have to provide a few initialization variables and everything else will take care of itself.  In the end the Data Mapper pattern is not that bad and fits in quite nicely with Zend Framework.  Other systems manage relationships for you but if you look at the Data Mapper pattern in detail adding that functionality into the mapper class itself should be trivial.</p>
<p><strong>Edit:</strong><br />
Here is an additional thought on this pattern.  The above mapper&#8217;s save function is built on specific schema that has two columns as primary keys.  If you have just one column and the primary key&#8217;s identifier is &#8220;id&#8221;, here is what a mapper&#8217;s save function might look like:</p>
<p><code></p>
<pre style="font-size:10px;">
    public function save(Application_Model_User $user) {
        $data = $user->toArray();

        foreach($this->ignoreProperties as $property) {
            if(isset($data[$property])) {
                unset($data[$property]);
            }
        }

        if(($id = $data['id']) !== null) {
            $this->getDbTable()->update($data, array('id = ?'=>(int)$id));
        } else {
            unset($data['id']);
            $user->id = $this->getDbTable()->insert($data);
        }
    }
</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://anthonyw.net/2012/02/the-data-mapper-pattern-its-pretty-good-heres-why/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>5</slash:comments>
		</item>
	</channel>
</rss>

