<?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>Devlog &#187; Check It Out</title>
	<atom:link href="http://devlog.info/cat/check-it-out/feed/" rel="self" type="application/rss+xml" />
	<link>http://devlog.info</link>
	<description>One developers blog.</description>
	<lastBuildDate>Tue, 31 Aug 2010 18:45:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP Stream Wrappers</title>
		<link>http://devlog.info/2008/10/19/php-stream-wrappers/</link>
		<comments>http://devlog.info/2008/10/19/php-stream-wrappers/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 20:24:53 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[Check It Out]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[stream-wrapper]]></category>

		<guid isPermaLink="false">http://devlog.info/?p=57</guid>
		<description><![CDATA[If you talk to me regularly then you already know how much I love stream wrappers in PHP. The other day I was positively giddy with how easy it was to solve a particular problem by using stream wrappers. 
What are stream wrappers?
PHP 4.3.0 introduced the idea of streams. The PHP manual has a perfect [...]]]></description>
			<content:encoded><![CDATA[<p>If you talk to me regularly then you already know how much I love stream wrappers in PHP. The other day I was positively giddy with how easy it was to solve a particular problem by using stream wrappers. <span id="more-57"></span></p>
<h2>What are stream wrappers?</h2>
<p>PHP 4.3.0 introduced the idea of streams. The <a href="http://php.net/manual/en/intro.stream.php">PHP manual</a> has a perfect explanation:</p>
<blockquote><p>Streams were introduced with PHP 4.3.0 as a way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream is a resource object which exhibits streamable behavior. That is, it can be read from or written to in a linear fashion, and may be able to fseek() to an arbitrary locations within the stream. </p></blockquote>
<p>Streams are identified by a particular scheme in the URI. For example, with <code>http://someurl</code> the scheme is 'http' and when no scheme is provided like in <code>/file.php</code>, the scheme is defaulted to 'file' and is expected to be a file in the filesystem (thus <code>file:///file.php</code> would mean the same thing).</p>
<p><strong>Stream wrappers</strong> are bits of code that tell PHP how to handle certain schemes. The interesting thing is that you can create your own custom stream wrappers written in PHP with little effort.</p>
<p>For example, you may have done <code>file_get_contents('file.txt');</code> before. But say you wanted to have the same ease of use but with data from a different source. You could create a custom stream wrapper to get data from wherever you want and use all of the normal PHP functions as usual: <code>file_get_contents('mystream://whatever');</code>.</p>
<p>Almost <em>any</em> function that works on files will work with custom stream wrappers. That includes fopen, fwrite, fseek, is_readable, is_writable, stat, unlink and more. In essence you can create a virtual filesystem in your applications.</p>
<h2>Why create custom stream wrappers?</h2>
<p>So why in the world would you want to create custom stream wrappers? Basically it comes down to decoupling filesystem-coupled interfaces from the filesystem (or any <em>stream</em>, for that matter). That is, make software think it's talking to files when it's talking to your custom PHP class. It's all about abstraction!</p>
<p>You could also use stream wrappers to simplify an interface, though this is less common. If you are using stream wrappers to simplify an interface, you can just as easily create a normal <a href="http://en.wikipedia.org/wiki/Facade_pattern">facade</a> to simplify the interface and leave streams out of it.</p>
<h3>For example</h3>
<p>I wanted to use a newish PHP templating engine called <a href="http://dwoo.org/">Dwoo</a> for an upcoming project. The problem was it expects files everywhere. Template files were read from the filesystem and compiled to the filesystem, and caches were written to the filesystem. There was no easy way to change this.</p>
<p>For this particular project I need to read templates from a string (loaded from an arbitrary source decided at runtime), and I can't use the filesystem for caches, I need to use memcached. The reason being that the application will be run in a cluster. Using shared disks is not practical with this many machines, and disk IO would eventually become a bottleneck. True, we could use RAM disks, but it's a lot easier and portable to manage the data layer from our application instead of pushing it to the OS.</p>
<p>Using custom stream wrappers I created two new schemes for 'tpl://' (for reading) and 'tplc://' (for writing compiled templates). I was able to fill the requirements for the project while still using the awesome templating engine with little modification. The library still thinks it's reading and writing to files but behind the scenes it's reading from a cache of template sources and writing to memcached. Perfect!</p>
<h2>Creating custom stream wrappers</h2>
<p>To create your own custom stream wrappers you need to write a class that implements a set of methods. After you write the class, you can register it with <a href="http://php.net/manual/en/function.stream-wrapper-register.php">stream_wrapper_register</a>. Refer to that manual page for details on the methods you need.</p>
<p>The only problem I encountered was how to get my custom stream working with is_readable() and is_writable(). The trick is to implement the 'url_stat' method and set the 'mode' correctly. The mode is a number that represents what type of file the file is (file or directory etc) and the file permissions -- the usual chmod values. Here's a code snippet that accurately defines how the number should add up:</p>
<pre id="raw-php-2" style="display:none; width: 1px; height: 1px; overflow: hidden;">$dir = 040000;
$file = 0100000;

// Now you can add any permissions you want using the usual chmod octal notation:
$file += 0777; // A file that is readable
$dir += 0222; // A directory that is writable</pre>
<div class="igBar">
<div class="wrap"><span id="lphp-2" style="float:right"><a href="#" onclick="javascript:showCodeTxt('php-2'); return false;">Plain Text</a></span><span class="langName">PHP:</span>
</div>
</div>
<div class="syntax_hilite">
<div class="wrap">
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$dir</span> = <span style="color:#CC66CC;color:#800000;">040000</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$file</span> = <span style="color:#CC66CC;color:#800000;">0100000</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Now you can add any permissions you want using the usual chmod octal notation:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$file</span> += <span style="color:#CC66CC;color:#800000;">0777</span>; <span style="color:#FF9933; font-style:italic;">// A file that is readable</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$dir</span> += <span style="color:#CC66CC;color:#800000;">0222</span>; <span style="color:#FF9933; font-style:italic;">// A directory that is writable </span></div>
</li>
</ol>
</div>
</div>
</div>
</div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://devlog.info/2008/10/19/php-stream-wrappers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Certification</title>
		<link>http://devlog.info/2008/04/21/php-certification/</link>
		<comments>http://devlog.info/2008/04/21/php-certification/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 01:14:30 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[Check It Out]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[certification]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://devlog.info/?p=31</guid>
		<description><![CDATA[I get asked about this a lot. Why did I take the PHP Certification exam? What does it do for me? Was it hard?
The Zend PHP Certification is basically a badge that says "I know my stuff". Zend's site actually has a pretty good summary of the benefits of becoming certified.
I became certified for a [...]]]></description>
			<content:encoded><![CDATA[<p>I get asked about this a lot. Why did I take the PHP Certification exam? What does it do for me? Was it hard?<span id="more-31"></span></p>
<p>The <a href="http://www.zend.com/en/services/certification/">Zend PHP Certification</a> is basically a badge that says "I know my stuff". Zend's site actually has a pretty good summary of the benefits of becoming certified.</p>
<p>I became certified for a couple of reasons (other than me being an egotistical bastard). I wanted to test myself and make sure I was actually up to date with everything. I came into the world of PHP around version 4.1. Since then a lot has changed, especially with the advent of PHP5. Taking the practice exams I discovered that there were a few areas I definitely needed to improve upon. For example, primarily working on products that needed to run under a PHP4, I never had much experience with the new XML features.</p>
<p>The other reason was that the exam was really cheap for the possible benefit. Noted, the Zend PHP Certification is hardly mentioned at all by employers. It is relatively new as far as certifications go. But by sticking that badge on your resume, you automatically have a one-up over your adversaries. PHP programmers are a dime a dozen these days, and most of them only know enough to slap together something that barely works. If a possible client knows you've passed the official PHP Certification exam, it gives you some credibility. $125 is a small price to pay. You can make that back in just a single job.</p>
<h3>Preparation</h3>
<p>I know you're thinking it. Everyone whose asked me about the exam always asks "was it hard?". <em>For me</em>, it was simple. I found it really easy. But I've been working with PHP for a long long time, so obviously your milage may vary (it's all relative, after all).</p>
<p>What you really need to do is a little research. I ended up buying the <a href="http://www.zend.com/en/store/php-certification/study-guide">bundle</a> which included the study guide, 10 practice exams, and the actual exam voucher. It's a pretty good deal, I encourage anyone interested in taking the exam to do the same.</p>
<p>The study guide was not bad. It's basically a quick walkthrough over the entire language. But the practice exams were really useful. The practice exams tell you if you're really ready to take the real thing. I can tell you, they are very very close to the real exam; they are actually a bit harder. If you pass the practice exams, you will surely pass the real exam.</p>
<p>After you finish a practice exam, you get a scorecard telling you which areas you passed, which you failed, and which you did excellent in. For me, this scorecard revealed I needed to brush up with SimpleXML.</p>
<p>I should mention that the exam is a pass or fail thing. There are no grades. My PHP Certification can not be better than yours. So just because you get "pass" instead of "excellent" doesn't really matter unless your ego requires it (like mine!).</p>
<h3>What you should know</h3>
<p>The Zend website has an <a href="http://www.zend.com/en/services/certification/php5-certification">overview</a> of the topics covered by the exam. Of course you need to know every inch of PHP, but I will point-out/stress:</p>
<ul>
<li>Regular expressions: You should know some basic regex.</li>
<li>SQL: You will need to know some basic SQL, and how it works (i.e., fetching rows with PDO). Some topics you might need to brush up on include indexes, table joins and transactions. You don't need to be a DBA to pass the exam, but you should know how to work with a database.</li>
<li>How numbers are represented in hex or octal notation. I mention this here because a lot of us don't need to worry about hex or octal notation in PHP.</li>
<li>How the bitwise operators work.</li>
<li>Differences between PHP4 and PHP5. There are a bunch of little nuances here that you may be asked about.</li>
<li>Security: You should know things like how to avoid XSS, session fixation, filtering input, validation etc.</li>
<li>XML: There may be a number of questions about XML, XPath, SimpleXML etc. If you've been working with PHP4 a lot, then it's time to get in tune with the improvements PHP5 introduced.</li>
<li>PDO: If you've been working with a database abstraction layer (which is probably just about everyone reading this), then you probably will need to read up on how PDO works.</li>
<li>There may be a few questions regarding software architecture such as design patterns (MVC for example), OOP principals etc.</li>
<li>Streams and network programming is something you will probably need to look into a bit.</li>
</ul>
<h3>Who should take the exam</h3>
<p>You should only take the exam if you actually know PHP well. It does an excellent job at weeding out the half-assed PHP programmers, so don't even attempt it unless you know your stuff already. If you are just starting out, or are of average skill, your money would be best spent buying some other material like <a href="http://www.amazon.com/Advanced-PHP-Programming-Developers-Library/dp/0672325616">Advanced PHP Programming</a>.</p>
<p>You should take the exam if you are a freelancer, or looking for work. I think it definitely does give you a heads up over your competition. Even if you have other credentials. Case in point: recently I was looking for a new programmer to help develop a product I work on. One applicant was a CS major, but was an absolutely horrible programmer. You might have passed a few college classes, but that doesn't mean much to me. I need to know that you can deliver.</p>
<p>You should take the exam if you want to test yourself, like I did. It is certainly a good way to discover your weaknesses and your strengths. You might find multiple areas where you had no experience.</p>
<p>So with all that said, good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://devlog.info/2008/04/21/php-certification/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sounds, IE7 and Security Warnings</title>
		<link>http://devlog.info/2008/04/11/sounds-ie7-security-warnings/</link>
		<comments>http://devlog.info/2008/04/11/sounds-ie7-security-warnings/#comments</comments>
		<pubDate>Fri, 11 Apr 2008 23:33:40 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[Check It Out]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[ie7]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[sound]]></category>
		<category><![CDATA[sound manager]]></category>

		<guid isPermaLink="false">http://devlog.info/?p=30</guid>
		<description><![CDATA[Some of you may know that the last few weeks I've been writing an AJAX chat application that plugs in to DeskPRO. One of the problems we ran into is playing sound notifications. The problem is that IE7 likes to pop up a security warning when you use the usual &#60;embed&#62; code. This was unacceptable. [...]]]></description>
			<content:encoded><![CDATA[<p>Some of you may know that the last few weeks I've been writing an AJAX chat application that plugs in to DeskPRO. One of the problems we ran into is playing sound notifications. The problem is that IE7 likes to pop up a security warning when you use the usual &lt;embed&gt; code. This was unacceptable. So today I just want to briefly talk about how I solved the problem.<span id="more-30"></span></p>
<p>The solution that I came up with was to use Flash. Seeing as how over <a href="http://www.adobe.com/products/player_census/flashplayer/">98% of all users</a> have Flash installed, it was the perfect solution.</p>
<p>I ended up finding an open source project called <a href="http://www.schillmania.com/projects/soundmanager2/">Sound Manager</a>. You just embed the Flash movie on your page somewhere, and talk to it with plain old Javascript. You don't need Flash installed, you don't need to create your own movie -- all you do is use the API provided by Sound Manager.</p>
<p>For the curious ones amongst you, the API is really simple (taken directly from the linked page above):</p>
<pre id="raw-javascript-4" style="display:none; width: 1px; height: 1px; overflow: hidden;">soundManager.createSound('myNewSound','/path/to/some.mp3');

soundManager.play('myNewSound');
soundManager.setVolume('myNewSound',50);
soundManager.setPan('myNewSound',-100);</pre>
<div class="igBar">
<div class="wrap"><span id="ljavascript-4" style="float:right"><a href="#" onclick="javascript:showCodeTxt('javascript-4'); return false;">Plain Text</a></span><span class="langName">JAVASCRIPT:</span>
</div>
</div>
<div class="syntax_hilite">
<div class="wrap">
<div id="javascript-4">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">soundManager.<span style="color: #006600;">createSound</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'myNewSound'</span>,<span style="color: #3366CC;">'/path/to/some.mp3'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">soundManager.<span style="color: #006600;">play</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'myNewSound'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">soundManager.<span style="color: #006600;">setVolume</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'myNewSound'</span>,<span style="color: #CC0000;color:#800000;">50</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">soundManager.<span style="color: #006600;">setPan</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'myNewSound'</span>,-<span style="color: #CC0000;color:#800000;">100</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
</div>
<p></p>
<p>The <em>only</em> problem I had with using Sound Manager is that it requires MP3's, and all of our sounds were WAV's. No biggie. Converting the files to MP3's was simple, and the resulting filesize a bit smaller anyway.</p>
<h3>Even more accessible?</h3>
<p>98% of internet users have Flash. That's a pretty good percentage. But I still wanted to make sure those rare 2% of users didn't get some "install this plugin" popup.</p>
<p>Basically what I ended up doing was using a Flash sniffer (some JS to determine if Flash is installed, and which version) to see if the user can use the Sound Manager. If they could use it, then great -- we're all set to go. If they couldn't, then the app reverts back to using good ol'd &lt;embed&gt;'s (except for IE7; no sound is better then an annoying security popup!).</p>
]]></content:encoded>
			<wfw:commentRss>http://devlog.info/2008/04/11/sounds-ie7-security-warnings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>symfony Framework</title>
		<link>http://devlog.info/2007/06/10/symfony-framework/</link>
		<comments>http://devlog.info/2007/06/10/symfony-framework/#comments</comments>
		<pubDate>Sun, 10 Jun 2007 16:58:45 +0000</pubDate>
		<dc:creator>Christopher</dc:creator>
				<category><![CDATA[Check It Out]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devlog.info/2007/06/10/symfony-framework/</guid>
		<description><![CDATA[Yesterday I spent 6 or 7 hours working with the symfony framework. After investigating several other frameworks available, like CakePHP and CodeIgniter, I settled down to work with symfony and I'm glad I did. It has a pretty big learning curve, but the free book is an invaluable resource (I'm actually thinking of buying the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I spent 6 or 7 hours working with the <a href="http://www.symfony-project.com/">symfony framework</a>. After investigating several other frameworks available, like <a href="http://cakephp.org/">CakePHP</a> and <a href="http://codeigniter.com/">CodeIgniter</a>, I settled down to work with symfony and I'm glad I did. It has a pretty big learning curve, but the <a href="http://www.symfony-project.com/book/trunk">free book</a> is an invaluable resource (I'm actually thinking of buying the printed copy). The framework itself is great, and is built up of some excellent parts like <a href="http://propel.phpdb.org/trac/">Propel</a> for <acronym title="Object Relational Mapping">ORM</acronym> and <a href="http://creole.phpdb.org/trac/">Creole</a> for database abstraction. Even if you don't use symfony, check out those two open-source libraries, they are excellent.</p>
<p>Yesterday's time was spent both learning the framework and creating the upcoming Outershift website. In 6 hours I learned much and completed a good chunk of the back-end. Considering I started from scratch, I am very pleased with how quickly the project has progressed. So, check out the <a href="http://www.symfony-project.com/">symfony framework</a> for yourself!</p>
]]></content:encoded>
			<wfw:commentRss>http://devlog.info/2007/06/10/symfony-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
