<?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>Taha Bayrak</title>
	<atom:link href="http://www.tahabayrak.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.tahabayrak.com</link>
	<description>Software Architect - New York City Area</description>
	<lastBuildDate>Wed, 14 Apr 2010 14:53:35 +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>Drawbacks of HipHop</title>
		<link>http://www.tahabayrak.com/?p=38</link>
		<comments>http://www.tahabayrak.com/?p=38#comments</comments>
		<pubDate>Wed, 14 Apr 2010 14:53:35 +0000</pubDate>
		<dc:creator>Taha Bayrak</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[compile PHP to C++. C++]]></category>
		<category><![CDATA[hiphop]]></category>

		<guid isPermaLink="false">http://www.tahabayrak.com/?p=38</guid>
		<description><![CDATA[HipHop is a tool that converts PHP code into C++ code that when combined with a PHP compatible engine and extensions library. According to Haiping Zhao (Developer at Facebook), It can speed up applications by 50%. Currently, Facebook is serving 90% of its Web traffic using HipHop.
Compiling PHP to C is not a new idea. [...]]]></description>
			<content:encoded><![CDATA[<p>HipHop is a tool that converts PHP code into C++ code that when combined with a PHP compatible engine and extensions library. According to Haiping Zhao (Developer at Facebook), It can speed up applications by 50%. Currently, Facebook is serving 90% of its Web traffic using HipHop.</p>
<p>Compiling PHP to C is not a new idea. There were some open source projects like <a href="http://www.phpcompiler.org/">PHC</a>, <a href="http://www.roadsend.com/">Roadsend</a>. However it seems that HipHop is the most &#8216;practical&#8217; one among the others since it has been used to convert millions of lines of PHP in Facebook Server.</p>
<p>According to Facebook, the project was bridging the gap between PHP and C++ by static transformation. The transformation process includes three main steps:</p>
<p>   1. Static analysis<br />
   2. Type inference<br />
   3. Code generation </p>
<p>The main step that they gain performance is type inference since PHP is a weakly typed language. When the variables are converted to corresponding specific types in C++, they require less memory.<br />
There are some drawbacks that you need to consider before using HipHop in your porjects:</p>
<p>1- PHP 5.3 is not supported by HipHop. So, for now, forget about namespaces, late static binding if you decide to use HipHop.<br />
2- Some functions like &#8216;eval()&#8217; is not supported.<br />
3- If you&#8217;re using PHP extensions that is not included in HipHop project, you need to  convert them to C++ variants<br />
4- If you&#8217;re a &#8216;PHP on Windows&#8217; fan, you need to reconsider this since it doesn&#8217;t work on windows. </p>
<p>Check out HipHop wiki page for installation instructions and source code. </p>
<p>http://wiki.github.com/facebook/hiphop-php/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tahabayrak.com/?feed=rss2&amp;p=38</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleDB vs CouchDB</title>
		<link>http://www.tahabayrak.com/?p=35</link>
		<comments>http://www.tahabayrak.com/?p=35#comments</comments>
		<pubDate>Thu, 11 Mar 2010 16:52:12 +0000</pubDate>
		<dc:creator>Taha Bayrak</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[couchDB]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[simpleDB]]></category>

		<guid isPermaLink="false">http://www.tahabayrak.com/?p=35</guid>
		<description><![CDATA[Although some of the differences are outdated, here is a very useful blog post comparing Amazon&#8217;s SimpleDB with couchDB:
http://www.automatthew.com/2007/12/amazon-simpledb-and-couchdb-compared.html
]]></description>
			<content:encoded><![CDATA[<p>Although some of the differences are outdated, here is a very useful blog post comparing Amazon&#8217;s SimpleDB with couchDB:</p>
<p><a href="http://www.automatthew.com/2007/12/amazon-simpledb-and-couchdb-compared.html">http://www.automatthew.com/2007/12/amazon-simpledb-and-couchdb-compared.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tahabayrak.com/?feed=rss2&amp;p=35</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>POST vs PUT &#8211; Which one should be used in a RESTful app?</title>
		<link>http://www.tahabayrak.com/?p=23</link>
		<comments>http://www.tahabayrak.com/?p=23#comments</comments>
		<pubDate>Tue, 09 Mar 2010 17:17:04 +0000</pubDate>
		<dc:creator>Taha Bayrak</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[POST vs PUT]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[RESTful]]></category>

		<guid isPermaLink="false">http://www.tahabayrak.com/?p=23</guid>
		<description><![CDATA[PUT

It is used to create new resource or overwrite it.


PUT /&#40;action&#41;/ HTTP/1.1
Host: example.com

will create a new resource. Similarly,

PUT /&#40;action&#41;/ HTTP/1.1
Host: example.com

will update your existing resource.
POST

It is used to update (overwrite) an existing resource


POST /&#40;action&#41;/ HTTP/1.1
Host: example.com

will modify your resource. However,

POST /&#40;action&#41;/ HTTP/1.1
Host: example.com

will return a &#8216;resource not found&#8217; error.
For more information   visit W3.org [...]]]></description>
			<content:encoded><![CDATA[<p><strong>PUT</strong></p>
<ul>
<li><strong>It is used to create new resource or overwrite it.</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">PUT <span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span> HTTP<span style="color: #339933;">/</span><span style="color:#800080;">1.1</span>
Host<span style="color: #339933;">:</span> example<span style="color: #339933;">.</span>com</pre></div></div>

<p>will create a new resource. Similarly,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">PUT <span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span> HTTP<span style="color: #339933;">/</span><span style="color:#800080;">1.1</span>
Host<span style="color: #339933;">:</span> example<span style="color: #339933;">.</span>com</pre></div></div>

<p>will update your existing resource.</p>
<p><strong>POST</strong></p>
<ul>
<li><strong>It is used to update (overwrite) an existing resource</strong></li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">POST <span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span> HTTP<span style="color: #339933;">/</span><span style="color:#800080;">1.1</span>
Host<span style="color: #339933;">:</span> example<span style="color: #339933;">.</span>com</pre></div></div>

<p>will modify your resource. However,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">POST <span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>action<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span> HTTP<span style="color: #339933;">/</span><span style="color:#800080;">1.1</span>
Host<span style="color: #339933;">:</span> example<span style="color: #339933;">.</span>com</pre></div></div>

<p>will return a &#8216;resource not found&#8217; error.</p>
<p>For more information <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html">  visit W3.org </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tahabayrak.com/?feed=rss2&amp;p=23</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to rename a file uploaded with Zend_Form_Element_File</title>
		<link>http://www.tahabayrak.com/?p=11</link>
		<comments>http://www.tahabayrak.com/?p=11#comments</comments>
		<pubDate>Mon, 18 Jan 2010 06:40:52 +0000</pubDate>
		<dc:creator>Taha Bayrak</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[isvalid]]></category>
		<category><![CDATA[pathinfo]]></category>
		<category><![CDATA[rename]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<category><![CDATA[Zend_Form_Element_File]]></category>

		<guid isPermaLink="false">http://www.tahabayrak.com/?p=11</guid>
		<description><![CDATA[There are several ways of renaming files if you don&#8217;t want to use Zend_Form_Element component. However, the following is a ZF technique.Suppose you have a very basic form with a single file element:
Form.php

class My_Form extends Zend_Form
&#123;
    public function init&#40;&#41;
    &#123;
          [...]]]></description>
			<content:encoded><![CDATA[<p>There are several ways of renaming files if you don&#8217;t want to use Zend_Form_Element component. However, the following is a ZF technique.Suppose you have a very basic form with a single file element:<br />
<em>Form.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> My_Form <span style="color: #000000; font-weight: bold;">extends</span> Zend_Form
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$element</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Form_Element_File<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imagefile'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload an image:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDestination</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$uploaddir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* file directory */</span>
		<span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addValidator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Count'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addValidator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Size'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">202400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setRequired</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$element</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addValidator</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IsImage'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jpeg,jpg,png,gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$element</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'imagefile'</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>What you need to do is to override the isValid( .. ) method of your Form Object: </p>
<p><em>Form.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isValid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$oldname</span> <span style="color: #339933;">=</span> <span style="color: #990000;">pathinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imagefile</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFileName</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: #000088;">$newname</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getUniqueCode</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$oldname</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'extension'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imagefile</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addFilter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Rename'</span><span style="color: #339933;">,</span><span style="color: #000088;">$newname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you don&#8217;t want to loose your other validators , don&#8217;t forget to call the parent isValid() method . As you can see, I used PHP&#8217;s pathinfo() method to parse the file path. (There should be another one in ZF ). I renamed it with a string of 10 random characters, and kept the extension as it was. Below is the method that you can use for the random file name :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> getUniqueCode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
		<span style="color: #000088;">$code</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">uniqid</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</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: #000088;">$length</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> 
                       <span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$code</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> 
                       <span style="color: #b1b100;">return</span> <span style="color: #000088;">$code</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, in your controller, you basically check if the form is valid, </p>
<p><em>MyFormController.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"> <span style="color: #000088;">$request</span>	<span style="color: #339933;">=</span>	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$form</span>		<span style="color: #339933;">=</span>	<span style="color: #000000; font-weight: bold;">new</span> My_Form<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;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isPost</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>
&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;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPost</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;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$formData</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValues</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			try <span style="color: #009900;">&#123;</span>
				 <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">imagefile</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">receive</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				throw <span style="color: #000000; font-weight: bold;">new</span> Zend_Exception <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'There is a problem with the file upload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
			<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope it helps. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.tahabayrak.com/?feed=rss2&amp;p=11</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Db_Table vs Doctrine</title>
		<link>http://www.tahabayrak.com/?p=7</link>
		<comments>http://www.tahabayrak.com/?p=7#comments</comments>
		<pubDate>Mon, 18 Jan 2010 05:51:19 +0000</pubDate>
		<dc:creator>Taha Bayrak</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.tahabayrak.com/?p=7</guid>
		<description><![CDATA[A good blog post about an advantage of Doctrine over Zend_Db_Table:
http://roetgers.org/2009/10/21/why-i-prefer-propel-over-zend_db_table/
]]></description>
			<content:encoded><![CDATA[<p>A good blog post about an advantage of Doctrine over Zend_Db_Table:</p>
<p>http://roetgers.org/2009/10/21/why-i-prefer-propel-over-zend_db_table/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tahabayrak.com/?feed=rss2&amp;p=7</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
