<?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>TK Studios &#187; web development</title>
	<atom:link href="http://www.tkstudios.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tkstudios.com</link>
	<description>Web Application Design &#38; Development</description>
	<lastBuildDate>Tue, 27 Apr 2010 20:41:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP hashing performance experiment</title>
		<link>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/</link>
		<comments>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 05:26:52 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Listy]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=150</guid>
		<description><![CDATA[Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, [...]]]></description>
			<content:encoded><![CDATA[<p>Today, in the never-ending quest to tweak server performance by a few milliseconds, I decided to do a bit of testing of various php hashing methods. I therefore wrote a quick script under php (5.2.11 currently, I need to update), which ran each test case 10,000 times to achieve a decent min/avg/max for each case, on strings of 10KB, 100KB, and 1,000KB in size.</p>
<p>The short version of the result is that the md5() function won across the board. The comments in the <a title="PHP: hash - Manual" href="http://us.php.net/manual/en/function.hash.php">php.net hash function documentation</a> seemed to indicate a performance increase in using hash(&#8216;md5&#8242;,$str), and an even better increase in hash(&#8216;md4&#8242;,$str). I found this to only partially be the case; While using the hash function, md4 is minutely faster than md5, the md5() function itself is considerably faster than either of these.</p>
<p>So, for any performance sensitive case, I would say md5() is by far the best choice.</p>
<p>Actual results of the test suite can be seen here:</p>
<p><a href="http://listy.us/list/view/153"><img src="http://www.listy.us/list/banner/153" alt="PHP Hash Performance by JSylvanus via Listy.us" /></a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=PHP+hashing+performance+experiment+http://is.gd/dXqrM+(@tkstudios)" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=PHP+hashing+performance+experiment+http://is.gd/dXqrM+(@tkstudios)" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/&amp;title=PHP+hashing+performance+experiment" title="Post to StumbleUpon">Stumble This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2010/04/25/php-hashing-performance-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework: Email templating with layouts &amp; views</title>
		<link>http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/</link>
		<comments>http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 16:14:24 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Listy]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.tkstudios.com/?p=99</guid>
		<description><![CDATA[This is a solution that I came up with for sending out welcome emails, comment notifications, etc, with nice standardized HTML &#38; text layouts, using a few components of the Zend Framework. Basically you create a view (here called $renderer) and a layout ($layout), then render your views and layouts for both HTML and text [...]]]></description>
			<content:encoded><![CDATA[<p>This is a solution that I came up with for sending out welcome emails, comment notifications, etc, with nice standardized HTML &amp; text layouts, using a few components of the Zend Framework.</p>
<p>Basically you create a view (here called $renderer) and a layout ($layout), then render your views and layouts for both HTML and text versions. My file tree looks like this:</p>
<pre>
application/
	emails/
		welcome.html.phtml
		welcome.text.phtml
		layouts/
			layout.html.phtml
			layout.text.phtml
</pre>
<p>So, &#8216;welcome&#8217; would be your template name, with html and text versions. The layout is what you want wrapped around either version of every email you send out (header graphics, font settings, contact info, etc).</p>
<p>I keep all of my mail functions in one class, creating a new function for each email that needs to be sent out regularly in an automatic fashion. You could even use this for newsletters, but I prefer more robust environments like <a href="http://www.mailchimp.com/">MailChimp</a> or <a href="http://www.campaignmonitor.com/">CampaignMonitor</a> for that sort of thing.</p>
<p>This simple function handles all the rendering, file paths, etc. It just needs to be called with the proper template name, and an array of items to be passed to the view renderer.</p>
<p>Here&#8217;s the meat of it:</p>
<pre>/**
 * getMailContent
 * Renders mailer content in text and html and passes it back as an array('html'=>content,'text'=>content)
 *
 * @param string $templatename the name of the email template to use (APP/emails/[name].[format].phtml)
 * @param array $substitutions key=>value array of variables to pass to the view renderers
 * @return array
 */
public function getMailContent($templatename, $substitutions) {

    // create a view renderer and set it to app_path/emails/
    $renderer = new Zend_View();
    $renderer->setScriptPath(realpath(APPLICATION_PATH . '/emails/'));

    // create a layout object and set it to app_path/emails/layouts
    $layout = new Zend_Layout(APPLICATION_PATH . '/emails/layouts/');
    $layout->setView($renderer); // this probably isn't even necessary

    // assign all substitutions (e.g. view variables) to the view renderer
    foreach ($substitutions as $key => $sub) $renderer->$key = $sub;

    $output = array(); // output array        

    // render text version of template &#038; assign to output['text']
    $layout->content = $renderer->render($templatename . '.text.phtml');
    $layout->setLayout('layout.text');
    $output['text'] = $layout->render();

    // render html version of template &#038; assign to output['html']
    $layout->content = $renderer->render($templatename . '.html.phtml');
    $layout->setLayout('layout.html');
    $output['html'] = $layout->render();

    // all done, return output
    return $output;

}</pre>
<p>Nice and simple, huh? All you need to do is call it and then assign the output to your Zend_Mail object like so:</p>
<pre>        $bodies = $this->getMailContent('new_comment', array(
            'comment' => $comment,
            'comment_list' => $comment_list,
            'comment_user' => $comment_user,
            'list_owner' => $list_owner
        ));
        $mail->setBodyHtml($bodies['html']);
        $mail->setBodyText($bodies['text']);</pre>
<p>Your email template accesses the variables passed to it just as it would a normal view script:
<pre>$this->[variable]</pre>
<p>Commentary / suggestions / etc welcome in comments.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Zend+Framework%3A+Email+templating+with+layouts+%26+views+http://is.gd/dXqe9+(@tkstudios)" title="Post to Twitter"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Zend+Framework%3A+Email+templating+with+layouts+%26+views+http://is.gd/dXqe9+(@tkstudios)" title="Post to Twitter">Tweet This Post</a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Digg"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-digg.png" alt="Post to Digg" /></a> <a class="tt" href="http://digg.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Digg">Digg This Post</a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Reddit"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-reddit.png" alt="Post to Reddit" /></a> <a class="tt" href="http://reddit.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to Reddit">Reddit</a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to StumbleUpon"><img class="nothumb" src="http://www.tkstudios.com/wp-content/plugins/tweet-this/icons/tt-su.png" alt="Post to StumbleUpon" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/&amp;title=Zend+Framework%3A+Email+templating+with+layouts+%26+views" title="Post to StumbleUpon">Stumble This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.tkstudios.com/2009/12/02/zend-framework-email-templating-with-layouts-views/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
