<?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>Rob Allen&#039;s DevNotes &#187; PHP</title>
	<atom:link href="http://akrabat.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://akrabat.com</link>
	<description>Developing PHP software in the Real World, by Rob Allen</description>
	<lastBuildDate>Fri, 03 Feb 2012 11:20:24 +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>Setting up PHP &amp; MySQL on OS X 10.7 Lion</title>
		<link>http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/</link>
		<comments>http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 07:05:17 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1580</guid>
		<description><![CDATA[With OS X 10.7, Apple continues to ship PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. This is how to set it up from a clean install of 10.7. /usr/local Ensure that the following directories exist: sudo mkdir /usr/local/include sudo mkdir /usr/local/bin sudo mkdir /usr/local/lib sudo mkdir -p /usr/local/man/man1 MySQL Download the [...]]]></description>
			<content:encoded><![CDATA[<p>With OS X 10.7, Apple continues to ship PHP 5.3 with PEAR, GD and PDO_MYSQL out of the box. This is how to set it up from a clean install of 10.7.</p>
<h3>/usr/local</h3>
<p>Ensure that the following directories exist:</p>
<pre>
sudo mkdir /usr/local/include
sudo mkdir /usr/local/bin
sudo mkdir /usr/local/lib
sudo mkdir -p /usr/local/man/man1
</pre>
<h3>MySQL</h3>
<ol>
<li>Download the 64bit DMG version of MySQL 5.1.x (or 5.5.x) for OS X 10.6 from <a href="http://dev.mysql.com/downloads/mysql/">mysql.com</a> and install the pkg, the startup item and the pref pane.</li>
<li>Add <tt>/usr/local/mysql/bin</tt> to the path: <tt>vim ~/.bash_profile</tt> and add:
<pre>
export PATH=~/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH
export EDITOR=vim
</pre>
<p> at top of file. (Note that we set EDITOR whilst we are here so that svn is happy!)
</li>
<li>Set up MySQL root password:
<pre>
mysqladmin -u root password {new-password}
mysqladmin -u root -p{new-password} -h localhost password {new-password}
mysqladmin -u root -p{new-password} reload
</pre>
<p>Clear the history file by typing <tt>history -c</tt> so that {new-password} isn't in plain text on the disk.
</li>
<li>Now ensure that the mysql.sock file can be found by PHP:
<ol>
<li>Ensure that MySQL is running</li>
<li><tt>sudo mkdir /var/mysql</tt></li>
<li><tt>sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock</tt></li>
</ol>
</li>
</ol>
<h3>Apache</h3>
<ol>
<li><tt>cd /etc/apache2</tt></li>
<li>Give write permission the config file to root: <tt>sudo chmod u+w httpd.conf</tt></li>
<li><tt>sudo vim httpd.conf</tt></li>
<li>Find <tt>#LoadModule php5_module        libexec/apache2/libphp5.so</tt> and remove the leading <tt>#</tt></li>
<li>Find <tt>AllowOverride None</tt> within the <tt>&lt;Directory "/Library/WebServer/Documents"&gt;</tt>section and change to<tt>AllowOverride All</tt> so that .htaccess files will work.</li>
<li>Change permissions back: <tt>sudo chmod u-w httpd.conf</tt></li>
<li>Restart Apache by unticking and then ticking again the Web Sharing checkbox in System Preferences -> Sharing</li>
<li>Open Finder and navigate to <tt>/Library/WebServer/Documents/</tt> using <tt>shift+cmd+g</tt></li>
<li>Create a new folder called "orig" and place all files currently in the Documents folder into it. (note that it will ask for your password as the <tt>Documents</tt> folder is only writable by root.</li>
<li>Create a new file called info.php with <tt>&lt;?php phpinfo();</tt> inside it.
</li>
<li>Use Safari to navigate to http://localhost/info.php and check that the PHP version is displayed (5.3.6 at the time of writing).</li>
</ol>
<h3>php.ini</h3>
<ol>
<li><tt>cd /etc</tt></li>
<li><tt>sudo cp php.ini.default php.ini</tt></li>
<li><tt>sudo chmod ug+w php.ini</tt></li>
<li><tt>sudo chgrp admin php.ini</tt></li>
<li><tt>vim php.ini</tt> (assuming your user is a member of the admin group) and change settings appropriately. Change:
<pre>error_reporting  =  E_ALL | E_STRICT
display_errors = On
html_errors = On
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20090626"</pre>
<p>(I like to see my xdebug errors in bright orange!)<br />
Also, change all instances of <tt>/var/mysql/mysql.sock</tt> to <tt>/tmp/mysql.sock</tt>
</li>
</ol>
<h3>Xdebug</h3>
<p>Can't have a PHP development environment without <a href="http://www.xdebug.org/">xdebug</a>! Apple appears to agree as Lion ships with it.</p>
<ol>
<li>vim /etc/php.ini</li>
<li>Find the line:<br />
<tt>;zend_extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so"</tt><br />
and remove the semicolon at the start</li>
<li>If you want to configure your xdebug settings, then scroll to the end of the file and look for the <tt>[xdebug]</tt> section. I like these settings:
<pre>
xdebug.var_display_max_children = 999
xdebug.var_display_max_data = 99999
xdebug.var_display_max_depth = 100
</pre>
<p>(use with caution…)</li>
<li>Restart apache: <tt>sudo apachectl restart</tt> and check in the phpinfo that xdebug is now loaded.</li>
</ol>
<h3>PEAR</h3>
<p>We need PEAR! For some reason, it's not set up ready to on Lion, but the install phar file is here, so we just need to run it.</p>
<ol>
<li>cd /usr/lib/php</li>
<li><tt>sudo php install-pear-nozlib.phar</tt></li>
<li>Edit<tt>/etc/php.ini</tt> and find the line: <tt>;include_path = ".:/php/includes"</tt> and change it to:<br />
<tt>include_path = ".:/usr/lib/php/pear"</tt></li>
<li><tt>sudo pear channel-update pear.php.net</tt></li>
<li><tt>sudo pecl channel-update pecl.php.net</tt></li>
<li><tt>sudo pear upgrade-all</tt></li>
</ol>
<h3>PHPUnit and friends</h3>
<p>I assume that everyone needs these…</p>
<ol>
<li><tt>sudo pear channel-discover pear.phpunit.de</tt></li>
<li><tt>sudo pear channel-discover components.ez.no</tt></li>
<li><tt>sudo pear channel-discover pear.symfony-project.com</tt></li>
<li><tt>sudo pear install phpunit/PHPUnit</tt></li>
<li><tt>sudo pear install phpunit/phpcpd</tt></li>
<li><tt>sudo pear install PHP_CodeSniffer</tt></li>
</ol>
<h3>PECL OAuth</h3>
<p>A couple of projects I work on use the PECL <a href="http://php.net/manual/en/book.oauth.php">OAuth</a> component:</p>
<ol>
<li>Ensure you have installed Xcode from the Mac App Store</li>
<li>Download the latest PCRE source code from <a href="http://sourceforge.net/projects/pcre/files/pcre/">http://sourceforge.net/projects/pcre/files/pcre/</a> and unzip to a folder on your desktop</li>
<li><tt>cd ~/Desktop/pcre-8.12</tt></li>
<li><tt>./configure</tt></li>
<li><tt>sudo cp pcre.h /usr/include/</tt></li>
<li>Remove the pcre folder on your desktop as you don't need it any more</li>
<li><tt>sudo pecl install oauth</tt></li>
<li>Edit<tt>/etc/php.ini</tt> add these lines to the end of the file:
<pre>[oauth]
extension="/usr/lib/php/extensions/no-debug-non-zts-20090626/oauth.so"</pre>
</li>
<li>Restart apache: <tt>sudo apachectl restart</tt> and check in the phpinfo that OAuth is now loaded.</li>
</ol>
<h3>mcrypt</h3>
<p>This is useful! Follow the installation details by Michale Gracie here: <a href="http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/">http://michaelgracie.com/2011/07/21/plugging-mcrypt-into-php-on-mac-os-x-lion-10-7/</a>)</p>
<p>It all works on this machine, anyway :)</p>
<h3>Other options</h3>
<p>If you'd rather use a packaged version, then these are two alternatives:</p>
<ul>
<li><a href="http://php-osx.liip.ch/">PHP 5.3 for OS X as binary package</a></li>
<li><a href="http://www.zend.com/en/products/server-ce/downloads">Zend Server CE</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/setting-up-php-mysql-on-os-x-10-7-lion/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>Great PHP developer required in Central Birmingham</title>
		<link>http://akrabat.com/php/great-php-developer-required-in-central-birmingham/</link>
		<comments>http://akrabat.com/php/great-php-developer-required-in-central-birmingham/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 21:15:35 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1488</guid>
		<description><![CDATA[Update: This position has now been filled. So... we seem to be in the same position as everyone else and are looking to hire a new, great, PHP developer! From the spec: Big Room Internet are looking for a great PHP software engineer to bring depth to the team and spearhead our future development. You [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> This position has now been filled. </p>
<p>So... we seem to be in the same position as everyone else and are looking to hire a new, great, PHP developer!</p>
<p>From <a href="http://www.bigroominternet.co.uk/about/we-are-recruiting">the spec</a>:</p>
<blockquote><p>Big Room Internet are looking for a great PHP software engineer to bring depth to the team and spearhead our future development. You will be working across a range of projects, ideally with experience in seeing through a project from start to finish. You will also interact with customers from taking work requests through to working with them to resolve an issue and get new software approved. You must be self motivated and be able to show that you can work on your own initiative.</p>
<p>Ideally you'll have several years of PHP website experience, but also the knowledge of best practices when working as a team on projects. You will be able to take the lead on technical decisions for projects along with documenting them and proving that they work.</p>
<p>This position is based in our office in central Birmingham.</p></blockquote>
<p>Obviously, we do a fair amount of our work using Zend Framework :)</p>
<p>If you're interested or if you know someone who is, please get them to contact me :)</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/great-php-developer-required-in-central-birmingham/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Displaying an RSS feed in WordPress</title>
		<link>http://akrabat.com/php/displaying-an-rss-feed-in-wordpress/</link>
		<comments>http://akrabat.com/php/displaying-an-rss-feed-in-wordpress/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 09:05:31 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1399</guid>
		<description><![CDATA[My wife decided that she wanted to display a list of her latest AudioBoos in the sidebar of her blog. She looked at the AudioBoo JavaScript widget but decided it wasn't subtle enough and so she enlisted me to solve her problem. It turns out that AudioBoo has an RSS feed, so a simple plugin [...]]]></description>
			<content:encoded><![CDATA[<p>My wife decided that she wanted to display a list of her latest AudioBoos in the sidebar of her blog. She looked at the AudioBoo JavaScript widget but decided it wasn't subtle enough and so she enlisted me to solve her problem.</p>
<p>It turns out that AudioBoo has an RSS feed, so a simple plugin was required. I had a quick look on the extension site, but most are now "widgets" which her theme isn't set up for or didn't provide an unsigned list. Hence, I whipped up a small extension for her.</p>
<p>It turns out that WordPress ships with <a href="http://magpierss.sourceforge.net/">MagpieRSS</a> baked in, so the work to get the feed is trivial:</p>
<pre class="phpcode"><span style="color: #0000BB">include_once</span><span style="color: #007700">(</span><span style="color: #0000BB">ABSPATH&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">WPINC&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'/rss.php'</span><span style="color: #007700">);
</span><span style="color: #0000BB">$messages&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fetch_rss</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">);</span>
</span></code></pre>
<p>The rest of the work is simply formatting the output. The key requirement that she had was that it should provide an unsigned list with title, date and optionally the summary. Along with providing some customisation for her, this is what I came up with:</p>
<pre class="phpcode"><span style="color: #0000BB">function&nbsp;akrabat_simple_rss</span><span style="color: #007700">(</span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;array())&nbsp;
{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$defaults&nbsp;</span><span style="color: #007700">=&nbsp;array(
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'url'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'number_of_items'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'display_date'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'date_format'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'d&nbsp;M&nbsp;Y&nbsp;at&nbsp;H:i'</span><span style="color: #007700">,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'display_summary'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'number_of_summary_chars'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">100</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'link_on_title'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'link_on_date'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'css_class'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'akrabat-simple-rss'</span><span style="color: #007700">,
&nbsp;&nbsp;&nbsp;&nbsp;);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">extract&nbsp;</span><span style="color: #007700">(</span><span style="color: #0000BB">array_merge</span><span style="color: #007700">(</span><span style="color: #0000BB">$defaults</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">));
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!empty(</span><span style="color: #0000BB">$url</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include_once(</span><span style="color: #0000BB">ABSPATH&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">WPINC&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">'/rss.php'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$messages&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fetch_rss</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$messages</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">items</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(</span><span style="color: #0000BB">$number_of_items&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$messages</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">items</span><span style="color: #007700">))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$number_of_items&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$messages</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">items</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'&lt;ul&nbsp;class="'</span><span style="color: #007700">.</span><span style="color: #0000BB">$css_class</span><span style="color: #007700">.</span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">$number_of_items</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$message&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$messages</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">items</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'link'</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$title&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'title'</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$date&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(isset(</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'published'</span><span style="color: #007700">]))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$date&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'published'</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$date&nbsp;</span><span style="color: #007700">&amp;&amp;&nbsp;isset(</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'pubdate'</span><span style="color: #007700">]))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$date&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'pubdate'</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$summary&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(isset(</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'summary'</span><span style="color: #007700">]))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$summary&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'summary'</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">$summary&nbsp;</span><span style="color: #007700">&amp;&amp;&nbsp;isset(</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'description'</span><span style="color: #007700">]))&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$summary&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$message</span><span style="color: #007700">[</span><span style="color: #DD0000">'description'</span><span style="color: #007700">];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"&lt;li&gt;"</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$title_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">$title_string</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$link_on_title</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="'</span><span style="color: #007700">.</span><span style="color: #0000BB">$link</span><span style="color: #007700">.</span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$title_string</span><span style="color: #007700">.</span><span style="color: #DD0000">'&lt;/a&gt;'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">'&lt;div&nbsp;class="akrabat-rss-title"&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$title_string</span><span style="color: #007700">.</span><span style="color: #DD0000">'&lt;/div&gt;'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$date&nbsp;</span><span style="color: #007700">&amp;&amp;&nbsp;</span><span style="color: #0000BB">$display_date</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$dateString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">$date_format</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">));
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$link_on_date</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$dateString&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'&lt;a&nbsp;href="'</span><span style="color: #007700">.</span><span style="color: #0000BB">$link</span><span style="color: #007700">.</span><span style="color: #DD0000">'"&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$dateString</span><span style="color: #007700">.</span><span style="color: #DD0000">'&lt;/a&gt;'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">'&lt;div&nbsp;class="date"&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$dateString</span><span style="color: #007700">.</span><span style="color: #DD0000">'&lt;/div&gt;'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$summary&nbsp;</span><span style="color: #007700">&amp;&amp;&nbsp;</span><span style="color: #0000BB">$display_summary</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$summary_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$summary</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$number_of_summary_chars</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">summary</span><span style="color: #007700">)&nbsp;&gt;&nbsp;</span><span style="color: #0000BB">$number_of_summary_chars</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$summary_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">summary_string</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;-</span><span style="color: #0000BB">3</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'...'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$summary_string&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">htmlspecialchars</span><span style="color: #007700">(</span><span style="color: #0000BB">$summary_string</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">'&lt;div&nbsp;class="summary"&gt;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$summary_string</span><span style="color: #007700">.</span><span style="color: #DD0000">'&lt;/div&gt;'</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"&lt;/li&gt;"</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$output&nbsp;</span><span style="color: #007700">.=&nbsp;</span><span style="color: #DD0000">"&lt;/ul&gt;"</span><span style="color: #007700">;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$output</span><span style="color: #007700">;
}</span>
</span></code></pre>
<p>Maybe it's useful to someone else too, and I've documented it somewhere!</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/displaying-an-rss-feed-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP 5.3 is quicker than PHP 5.2</title>
		<link>http://akrabat.com/php/php-5-3-is-quicker-than-php-5-2-2/</link>
		<comments>http://akrabat.com/php/php-5-3-is-quicker-than-php-5-2-2/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 09:01:09 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1356</guid>
		<description><![CDATA[I know that everyone already knows this, but I happened to find out for myself recently! I was looking at the way view helpers work in ZF2 and thought it would be more convenient if we altered the syntax a little. A side-effect of the change was that we'd have to use call_user_func_array, which is [...]]]></description>
			<content:encoded><![CDATA[<p>I know that everyone already knows this, but I happened to find out for myself recently!</p>
<p>I was looking at the way view helpers work in ZF2 and thought it would be more convenient if we altered the syntax a little. A side-effect of the change was that we'd have to use <tt>call_user_func_array</tt>, which is perceived as slow. I thought I'd whip up a simple test to find out how much slower it would be over a direct method call.</p>
<p>That is, how much slower is this code:</p>
<pre class="phpcode"><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">();
</span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #0000BB">1</span><span style="color: #007700">));</span>
</span></code></pre>
<p>than this code:</p>
<pre class="phpcode"><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">();
</span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">b</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);</span>
</span></code></pre>
<p>Bear in mind that I don't do formal benchmarks and have no clue on methodology. <a href="http://paul-m-jones.com/archives/category/programming/benchmarks">Paul Jones</a> is your man for proper testing of performance.</p>
<p>With that caveat out of the way this is the code I wrote to test:</p>
<p><strong>benchmark.php</strong></p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php

</span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">A
</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">b</span><span style="color: #007700">(</span><span style="color: #0000BB">$a</span><span style="color: #007700">)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;
&nbsp;&nbsp;&nbsp;&nbsp;}
}

</span><span style="color: #0000BB">define&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">'ITERATIONS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10000000</span><span style="color: #007700">);
</span><span style="color: #0000BB">$start&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);
</span><span style="color: #0000BB">$a&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">();
for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">ITERATIONS</span><span style="color: #007700">;&nbsp;++</span><span style="color: #0000BB">$i</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$a</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">b</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);
}
</span><span style="color: #0000BB">$stop&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);
echo&nbsp;&nbsp;</span><span style="color: #DD0000">'Direct&nbsp;method&nbsp;call:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;(</span><span style="color: #0000BB">$stop&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">$start</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;seconds'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;&nbsp;

</span><span style="color: #0000BB">$start&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);
for&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">ITERATIONS</span><span style="color: #007700">;&nbsp;++</span><span style="color: #0000BB">$i</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$a</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">),&nbsp;array(</span><span style="color: #0000BB">1</span><span style="color: #007700">));
}
</span><span style="color: #0000BB">$stop&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">microtime</span><span style="color: #007700">(</span><span style="color: #0000BB">true</span><span style="color: #007700">);
echo&nbsp;&nbsp;</span><span style="color: #DD0000">'call_user_func_array&nbsp;call:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;(</span><span style="color: #0000BB">$stop&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">$start</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">'&nbsp;seconds'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;&nbsp;
</span>
</span></code></pre>
<p>This was the simplest possible scenario I could imagine and so would show <tt>call_user_func_array</tt> in the best possible light. </p>
<p>I ran the test on my laptop (using the command line) and got these results:</p>
<pre class="phpcode"><span style="color: #0000BB">
Direct&nbsp;method&nbsp;call</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">21.155211925507&nbsp;seconds
call_user_func_array&nbsp;call</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">72.147792100906&nbsp;seconds
</span>
</span></code></pre>
<p>i.e. <tt>call_user_func_array</tt> is around 3.5 times slower over 10 million iterations.</p>
<p>Nobody uses their laptop to serve a website though! Being the curious sort, I thought I'd test the difference of this script between PHP 5.2 and PHP 5.3 in a completely unscientific way as I'm lazy! I happen to have a server with both PHP 5.2 and PHP 5.3. on it, so I used that:</p>
<p>PHP 5.2:</p>
<pre class="phpcode"><span style="color: #0000BB">
Direct&nbsp;method&nbsp;call</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">8.3424661159515&nbsp;seconds
call_user_func_array&nbsp;call</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">26.904649972916&nbsp;seconds
</span>
</span></code></pre>
<p>PHP 5.3:</p>
<pre class="phpcode"><span style="color: #0000BB">
Direct&nbsp;method&nbsp;call</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">3.35181903839&nbsp;seconds
call_user_func_array&nbsp;call</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">11.5989868641&nbsp;seconds
</span>
</span></code></pre>
<p>As you can see, my server is much faster than my laptop :) Also, the relative difference is the same. i.e. PHP 5.3's <tt>call_user_func_array</tt> is as slow as it is in PHP 5.2.</p>
<p>I think I'll move everything to PHP 5.3 for the free performance gain! Of course, The question remains as to whether we should avoid <tt>call_user_func_array</tt> or not.</p>
<p>I would however recommend testing your own apps and see if it makes any difference and <em>please</em> don't take this post as anything other than something interesting I found out!</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/php-5-3-is-quicker-than-php-5-2-2/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Some notes on SQL Server blobs with sqlsrv</title>
		<link>http://akrabat.com/php/some-notes-on-sql-server-blobs-with-sqlsrv/</link>
		<comments>http://akrabat.com/php/some-notes-on-sql-server-blobs-with-sqlsrv/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 08:01:45 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1320</guid>
		<description><![CDATA[I recently updated my use of SQL Server with Zend_Db_Adapter_Sqlsrv to use UTF-8 throughout. This turned out to be easy enough: Use ntext, nvarchar types in the database add: resources.db.params.driver_options.CharacterSet&#160;=&#160;"UTF-8" to your application.ini I subsequently noticed a problem with storing binary data to a varbinary(max) field. The error was: An error occurred translating string for [...]]]></description>
			<content:encoded><![CDATA[<p>I recently updated my use of SQL Server with Zend_Db_Adapter_Sqlsrv to use UTF-8 throughout. This turned out to be easy enough:</p>
<ul>
<li>Use ntext, nvarchar types in the database</li>
<li>add:
<pre class="phpcode"><span style="color: #0000BB">resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">params</span><span style="color: #007700">.</span><span style="color: #0000BB">driver_options</span><span style="color: #007700">.</span><span style="color: #0000BB">CharacterSet&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"UTF-8"</span>
</span></code></pre>
<p> to your application.ini </li>
</ul>
<p>I subsequently noticed a problem with storing binary data to a <tt>varbinary(max)</tt> field. The error was:</p>
<p><tt>An error occurred translating string for input param 2 to UCS-2: No mapping for the Unicode character exists in the target multi-byte code page.</tt></p>
<p>urgh!</p>
<p>The code looked something like this:</p>
<pre class="phpcode"><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">'filename'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">'test.gif'</span><span style="color: #007700">;
</span><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">"file_contents"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$binaryData</span><span style="color: #007700">;
</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);</span>
</span></code></pre>
<p>Fortunately, my friend <a href="http://elizabethmariesmith.com/">Elizabeth Smith</a>, pointed me in the right direction by suggesting I find out about bindings.  So I did some research and it turns out that I just need to use an array for the parameter that I pass into the <tt>update()</tt> or <tt>insert()</tt> method of <tt>Zend_Db_Adapter_Sqlsrv</tt>.</p>
<p>It turns out that all you need to do is change the '<tt>file_contents</tt>' element of the array to an array that also specifies the data type. The code I ended up with now looks something like this:</p>
<pre class="phpcode"><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">'filename'</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #DD0000">'test.gif'</span><span style="color: #007700">;
</span><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">"file_contents"</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$binaryData</span><span style="color: #007700">;
if&nbsp;(</span><span style="color: #0000BB">$adapter&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #DD0000">'Zend_Db_Adapter_Sqlsrv'</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">[</span><span style="color: #DD0000">"file_contents"</span><span style="color: #007700">]&nbsp;=&nbsp;array(</span><span style="color: #0000BB">$binaryData</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SQLSRV_PARAM_IN</span><span style="color: #007700">,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">SQLSRV_PHPTYPE_STREAM</span><span style="color: #007700">(</span><span style="color: #0000BB">SQLSRV_ENC_BINARY</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">SQLSRV_SQLTYPE_VARBINARY</span><span style="color: #007700">(</span><span style="color: #DD0000">'max'</span><span style="color: #007700">));
}
</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);</span>
</span></code></pre>
<p>And all is fine.</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/cc296183(SQL.90).aspx">list of constants for the Sql Server Driver for PHP</a> is helpfully available on MSDN and the documentation for <a href="http://msdn.microsoft.com/en-US/library/cc296184(v=SQL.90).aspx">sqlsrv_query()</a> is worth reading too!</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/some-notes-on-sql-server-blobs-with-sqlsrv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SqlSrv v2 and long field names</title>
		<link>http://akrabat.com/php/sqlsrv-v2-and-long-field-names/</link>
		<comments>http://akrabat.com/php/sqlsrv-v2-and-long-field-names/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 06:53:04 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1291</guid>
		<description><![CDATA[A good proportion of the projects my company undertakes end up on Windows servers with IIS and SQL Server and hence we use the SqlSrv PHP extension from Microsoft. We don't host any of these projects ourselves and leave it up to the client's IT department. This is the main reason that we use a [...]]]></description>
			<content:encoded><![CDATA[<p>A good proportion of the projects my company undertakes end up on Windows servers with IIS and SQL Server and hence we use the <a href="http://sqlsrvphp.codeplex.com/">SqlSrv PHP extension</a> from Microsoft. We don't host any of these projects ourselves and leave it up to the client's IT department. This is the main reason that we use a database abstraction layer, Zend_Db, in our case as we can swap the underlying database out with less hassle. </p>
<p>A couple of weeks ago, I came across a problem when installing our app onto the client's server. </p>
<p>It didn't work. </p>
<p>This was a surprise as we have a few Windows Server VMWare installations on which we had tested and they had worked fine. The most obvious differences were that this server was 32bit and that it was using v2 of the SqlSrv extension. As there were a number of differences from our usual fare to the client's install, so it took me a while to (a) build a install that exhibited the problem and (b) reduce the problem to something simple.</p>
<p>The error I was getting is this:</p>
<pre class="phpcode"><span style="color: #0000BB">exception&nbsp;</span><span style="color: #DD0000">'Zend_Db_Statement_Sqlsrv_Exception'&nbsp;</span><span style="color: #0000BB">with&nbsp;message&nbsp;
</span><span style="color: #DD0000">'[Microsoft][SQL&nbsp;Server&nbsp;Native&nbsp;Client&nbsp;10.0]String&nbsp;data,&nbsp;right&nbsp;truncation'&nbsp;
</span><span style="color: #0000BB">in&nbsp;C</span><span style="color: #007700">:\</span><span style="color: #0000BB">Websites</span><span style="color: #007700">\</span><span style="color: #0000BB">project1</span><span style="color: #007700">\</span><span style="color: #0000BB">library</span><span style="color: #007700">\</span><span style="color: #0000BB">Zend</span><span style="color: #007700">\</span><span style="color: #0000BB">Db</span><span style="color: #007700">\</span><span style="color: #0000BB">Statement</span><span style="color: #007700">\</span><span style="color: #0000BB">Sqlsrv</span><span style="color: #007700">.</span><span style="color: #0000BB">php</span><span style="color: #007700">:</span><span style="color: #0000BB">237
</span>
</span></code></pre>
<p>Googling failed me completely!</p>
<p>I eventually narrowed down the SQL statement that caused the problem:</p>
<pre class="phpcode"><span style="color: #0000BB">SELECT&nbsp;email_user_include_form_details&nbsp;FROM&nbsp;</span><span style="color: #DD0000">"forms"</span>
</span></code></pre>
<p>That's not especially complicated :)</p>
<p>At the point, I yelled for help which came in the form of <a href="http://blogs.msdn.com/brian_swan/">Brian Swan</a> of Microsoft. There's quite a few helpful MS guys around nowadays if you keep your ear close to the PHP community, which is really handy. Brian helped prove that I wasn't going mad and that there really was a problem.</p>
<p>We determined the problem to be that with <strong>v2 of the sqlsrv driver, you cannot have a fieldname longer than 30 characters</strong>.</p>
<p>Brian assured me that the team are aware of this and it will be fixed in a subsequent update of the driver. Also, it only affects the sqlsrv driver and not the pdo_sqlsrv driver. Hence, there are <strong>two workarounds</strong>:</p>
<p>1. Shorten your fieldnames to 30 characters or less<br />
2. Use pdo_sqlsrv</p>
<p>Smart readers will already be commenting that there isn't a <tt>Zend_Db_Adapter_Pdo_Sqlsrv</tt>  and they'd be right, but it isn't hard to write one :)</p>
<h4>Akrabat_Db_Adapter_Pdo_Sqlsrv</h4>
<p>I cobbled together an adapter that works for me and have put it on <a href="http://github.com/akrabat/Akrabat/blob/master/zf1/Akrabat/Db/Adapter/Pdo/Sqlsrv.php">github</a>. As it's not in the <tt>Zend_</tt> namespace, we have to use an additional key in the application.ini file so that it is loaded:</p>
<p><strong>application.ini:</strong></p>
<pre class="phpcode"><span style="color: #0000BB">resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">adapter&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Pdo_SqlSrv"
</span><span style="color: #0000BB">resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">params</span><span style="color: #007700">.</span><span style="color: #0000BB">adapterNamespace&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Akrabat_Db_Adapter"
</span><span style="color: #0000BB">resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">params</span><span style="color: #007700">.</span><span style="color: #0000BB">host&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">localhostSQLEXPRESS
resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">params</span><span style="color: #007700">.</span><span style="color: #0000BB">username&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">testuser
resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">params</span><span style="color: #007700">.</span><span style="color: #0000BB">password&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">testpassword
resources</span><span style="color: #007700">.</span><span style="color: #0000BB">db</span><span style="color: #007700">.</span><span style="color: #0000BB">params</span><span style="color: #007700">.</span><span style="color: #0000BB">dbname&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">testdatabase</span>
</span></code></pre>
<p>The key difference from a standard Zend_Db adapter is the use of the <tt>resources.db.params.adapterNamespace</tt> key which tells the system the full name of the class to load. </p>
<p>My limited testing shows that this adapter works with v2 of pdo_sqlsrv which solves my problem with fieldnames that are longer than 30 characters!</p>
<p>Unfortunately, I found out about this too late for Zend Framework 1.11, so I'll have to look at getting it into Zend Framework 2.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/sqlsrv-v2-and-long-field-names/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>On Exceptions</title>
		<link>http://akrabat.com/php/on-exceptions/</link>
		<comments>http://akrabat.com/php/on-exceptions/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 07:30:40 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1225</guid>
		<description><![CDATA[I've been reading the Proposal for Exceptions in ZF2 and like it. One thing that caught my attention was that it suggests that you can catch an interface. I hadn't heard of that ability before, so I pulled out my trusty text editor to have a play. Consider this code: &#60;?php namespace&#160;My;&#160; &#160; interface&#160;ExceptionInterface&#160;{}&#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I've been reading the <a href="http://framework.zend.com/wiki/display/ZFDEV2/Proposal+for+Exceptions+in+ZF2?showComments=false">Proposal for Exceptions in ZF2</a> and like it. One thing that caught my attention was that it suggests that you can catch an interface. I hadn't heard of that ability before, so I pulled out my trusty text editor to have a play.</p>
<p>Consider this code:</p>
<pre class="phpcode">
<span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">namespace&nbsp;</span><span style="color: #0000BB">My</span><span style="color: #007700">;&nbsp;
&nbsp;
interface&nbsp;</span><span style="color: #0000BB">ExceptionInterface&nbsp;</span><span style="color: #007700">{}&nbsp;
&nbsp;
class&nbsp;</span><span style="color: #0000BB">SplExceptionClass&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">InvalidArgumentException&nbsp;</span><span style="color: #007700">implements&nbsp;</span><span style="color: #0000BB">ExceptionInterface&nbsp;</span><span style="color: #007700">{}&nbsp;
class&nbsp;</span><span style="color: #0000BB">ExceptionClass&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">Exception&nbsp;</span><span style="color: #007700">implements&nbsp;</span><span style="color: #0000BB">ExceptionInterface&nbsp;</span><span style="color: #007700">{}&nbsp;

class&nbsp;</span><span style="color: #0000BB">A&nbsp;</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">throwAnSplException</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">SplExceptionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'oops'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;static&nbsp;function&nbsp;</span><span style="color: #0000BB">throwAMyException</span><span style="color: #007700">()
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw&nbsp;new&nbsp;</span><span style="color: #0000BB">ExceptionClass</span><span style="color: #007700">(</span><span style="color: #DD0000">'oops&nbsp;again'</span><span style="color: #007700">);
&nbsp;&nbsp;&nbsp;&nbsp;}
}
</span>
</span></code></pre>
<p>Within our <tt>My</tt> namespace, we have two exception classes and an exception interface that both classes implement. We also define a class <tt>\My\A</tt> as a vehicle for throwing the exceptions. This is the basis of how ZF2 exceptions will work without all the actual component implementations :)</p>
<p>Let's do some testing to look at what happens:</p>
<p><strong>Test 1</strong></p>
<pre class="phpcode"><span style="color: #0000BB">try&nbsp;</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">throwAMyException</span><span style="color: #007700">();
}
catch&nbsp;(</span><span style="color: #0000BB">ExceptionClass&nbsp;$e</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Caught&nbsp;\\My\\ExceptionClass\n"</span><span style="color: #007700">;
}</span>
</span></code></pre>
<p>As expected, this works. We catch the <tt>\My\ExceptionClass</tt> exception that was thrown.</p>
<p><strong>Test 2</strong></p>
<pre class="phpcode"><span style="color: #0000BB">try&nbsp;</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">throwAnSplException</span><span style="color: #007700">();
}
catch&nbsp;(</span><span style="color: #0000BB">ExceptionClass&nbsp;$e</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Caught&nbsp;\\My\\ExceptionClass\n"</span><span style="color: #007700">;
}</span>
</span></code></pre>
<p>As expected, we fail to catch <tt>\My\SplExceptionClass</tt> exception that was thrown as it is not related to the <tt>\My\ExceptionClass</tt> that we are trying to catch.</p>
<p><strong>Test 3</strong></p>
<pre class="phpcode"><span style="color: #0000BB">try&nbsp;</span><span style="color: #007700">{
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">A</span><span style="color: #007700">::</span><span style="color: #0000BB">throwAnSplException</span><span style="color: #007700">();
}
catch&nbsp;(</span><span style="color: #0000BB">ExceptionInterface&nbsp;$e</span><span style="color: #007700">)&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Caught&nbsp;\\My\\ExceptionInterface\n"</span><span style="color: #007700">;
}</span>
</span></code></pre>
<p>This time we are catching the <tt>\My\ExceptionInterface</tt> and it works! This surprised me and is very handy. </p>
<p>We now have the ability with ZF2 to be able to use different exception classes to represent different error types rather than using string comparison and, at the same time, we can have a single <tt>catch()</tt> for when we don't need that level of granularity.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/on-exceptions/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>MongoDB on OS X with the stock PHP installation</title>
		<link>http://akrabat.com/php/mongodb-on-os-x-with-the-stock-php-installation/</link>
		<comments>http://akrabat.com/php/mongodb-on-os-x-with-the-stock-php-installation/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 12:47:54 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=1038</guid>
		<description><![CDATA[MongoDB was mentioned a few times at tek and I said that I wanted to have a look at. Travis' article, MongoDB: A first look, came out a few days ago and piqued my interest further. Then Matthew sent me some source code that requires it. The stage was set for getting MongoDB working on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/">MongoDB</a> was mentioned a few times at <a href="http://tek.phparch.com/">tek</a> and I said that I wanted to have a look at.</p>
<p>Travis' article, <a href="http://www.travisswicegood.com/index.php/2010/05/31/mongodb-a-first-look">MongoDB: A first look</a>, came out a few days ago and piqued my interest further. Then <a href="http://weierophinney.net/matthew/">Matthew</a> sent me some source code that requires it. The stage was set for getting MongoDB working on my Mac.</p>
<h3>MongoDB</h3>
<p>I use <a href="http://github.com/mxcl/homebrew">homebrew</a> as a package manager for installing open source bits and bobs like couchdb, git, and hg. Installing MongoDB was simply a case of:</p>
<pre>brew install mongodb</pre>
<p>Once, installed there's a convenient LaunchAgent plist supplied so that mongodb starts with the computer:</p>
<pre>cp /usr/local/Cellar/mongodb/1.4.3-x86_64/org.mongodb.mongod.plist ~/Library/LaunchAgents
launchctl load -w ~/Library/LaunchAgents/org.mongodb.mongod.plist</pre>
<p>And at this point, MongoDB is installed on your Mac and Travis' article and the <a href="http://www.mongodb.org/display/DOCS/Tutorial">tutorial</a> work!</p>
<h3>The Mongo PHP extension</h3>
<p>If you've been following along here for a while, then you'll know that I use the <a href="/phposx">stock PHP that comes with Mac OS X</a>. I've been very happy with it so far and installed <a href="http://xdebug.org/">Xdebug</a> was easy enough using pecl, so I was hopeful that the mongo extension would be equally simple.</p>
<p>Turns out that it is!</p>
<pre>pecl install mongo</pre>
<p>Compiles the extension with no problems.</p>
<p>To add it to your PHP install, edit php.ini and add:</p>
<pre>extension=mongo.so</pre>
<p>A quick <tt>sudo apachectl restart</tt> and phpinfo() shows this:</p>
<p><img src="http://akrabat.com/wp-content/uploads/2010-06-mongodb_phpinfo.png" alt="MongoDB in phpinfo" border="0" width="450" height="218" /></p>
<p>All done! You can now get at MongoDB from your PHP scripts.</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/mongodb-on-os-x-with-the-stock-php-installation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending a file to IE using SSL</title>
		<link>http://akrabat.com/php/sending-a-file-to-ie-using-ssl/</link>
		<comments>http://akrabat.com/php/sending-a-file-to-ie-using-ssl/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 14:29:52 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=960</guid>
		<description><![CDATA[I keep coming across this one, so I'm noting it here so I can find it again. Internet Explorer doesn't like certain headers related to caching when you send it a file from an SSL site. The Microsoft knowledge base article, Internet Explorer is unable to open Office documents from an SSL Web site explains [...]]]></description>
			<content:encoded><![CDATA[<p>I keep coming across this one, so I'm noting it here so I can find it again.</p>
<p>Internet Explorer doesn't like certain headers related to caching when you send it a file from an SSL site. The Microsoft knowledge base article,<a href="http://support.microsoft.com/kb/316431"> Internet Explorer is unable to open Office documents from an SSL Web site</a> explains the problem quite well:</p>
<blockquote><p>When you attempt to open or download a Microsoft Office document (.doc file, .xls file, .ppt file, and so on) from a secure Web site in Internet Explorer, you may receive one of the following error messages, even though the document is available and downloaded from the server</p></blockquote>
<p>It turns out that the problem is directly due to sending these headers:</p>
<pre class="phpcode"><span style="color: #0000BB">
Pragma</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">no</span><span style="color: #007700">-</span><span style="color: #0000BB">cache&nbsp;&nbsp;
Cache</span><span style="color: #007700">-</span><span style="color: #0000BB">control</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">no</span><span style="color: #007700">-</span><span style="color: #0000BB">cache</span><span style="color: #007700">,</span><span style="color: #0000BB">max</span><span style="color: #007700">-</span><span style="color: #0000BB">age</span><span style="color: #007700">=</span><span style="color: #0000BB">0</span><span style="color: #007700">,</span><span style="color: #0000BB">must</span><span style="color: #007700">-</span><span style="color: #0000BB">revalidate
</span>
</span></code></pre>
<p>So, make sure you don't!</p>
<p>Incidentally, IE6 also gets upset if you set <tt>max-age</tt> to <tt>0</tt> and attachment to <tt>inline</tt>, so don't do that either!</p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/sending-a-file-to-ie-using-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirecting email whilst developing</title>
		<link>http://akrabat.com/php/redirecting-email-whilst-developing/</link>
		<comments>http://akrabat.com/php/redirecting-email-whilst-developing/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 07:25:02 +0000</pubDate>
		<dc:creator>Rob...</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://akrabat.com/?p=906</guid>
		<description><![CDATA[One common problem whilst developing is that you don't want to send emails out to the client (or their clients!). Ideally, we want to alter our development environment so that this doesn't happen, but still allows us to test the contents of emails that are sent by our web applications. Windows On Windows, the mail() [...]]]></description>
			<content:encoded><![CDATA[<p>One common problem whilst developing is that you don't want to send emails out to the client (or their clients!). Ideally, we want to alter our development environment so that this doesn't happen, but still allows us to test the contents of emails that are sent by our web applications.</p>
<h3>Windows</h3>
<p>On Windows, the <tt>mail()</tt> function uses SMTP over port 25. Unless you've changed your php.ini file, then it will try to connect to localhost in order to send an email. On Windows VM, I use <a href="http://www.lastcraft.com/fakemail.php">Fakemail</a>. This is an SMTP mail server written in perl (or python) that store emails as files into a given directory. When your web application sends an email, you check in the directory and look at the files created.  One top tip: alter the script to give each file a <tt>.txt</tt> extension. Then you can double click :)</p>
<p>Fakemail is also very useful in Linux/Mac if you are using the SMTP transport mail in Zend_Mail or Swiftmailer or whatever.</p>
<h3>Linux / OS X</h3>
<p>On the *nix based systems, <tt>mail()</tt> sends email using an application on the system called <em>sendmail</em> (or any number of compatible alternatives). By default it will call the <tt>sendmail</tt> binary, however you can change this in your php.ini with the <tt>sendmail_path</tt> setting. </p>
<p>I set my development boxes like this:</p>
<pre class="phpcode"><span style="color: #0000BB">
sendmail_path&nbsp;</span><span style="color: #007700">=&nbsp;/</span><span style="color: #0000BB">usr</span><span style="color: #007700">/</span><span style="color: #0000BB">local</span><span style="color: #007700">/</span><span style="color: #0000BB">bin</span><span style="color: #007700">/</span><span style="color: #0000BB">trapmail
</span>
</span></code></pre>
<p>Now, mail() will call my <tt>trapmail</tt> script. This script is trivial:</p>
<pre class="phpcode"><span style="color: #0000BB">
formail&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">R&nbsp;cc&nbsp;X</span><span style="color: #007700">-</span><span style="color: #0000BB">original</span><span style="color: #007700">-</span><span style="color: #0000BB">cc&nbsp;</span><span style="color: #007700">\
&nbsp;&nbsp;-</span><span style="color: #0000BB">R&nbsp;to&nbsp;X</span><span style="color: #007700">-</span><span style="color: #0000BB">original</span><span style="color: #007700">-</span><span style="color: #0000BB">to&nbsp;</span><span style="color: #007700">\
&nbsp;&nbsp;-</span><span style="color: #0000BB">R&nbsp;bcc&nbsp;X</span><span style="color: #007700">-</span><span style="color: #0000BB">original</span><span style="color: #007700">-</span><span style="color: #0000BB">bcc&nbsp;</span><span style="color: #007700">\
&nbsp;&nbsp;-</span><span style="color: #0000BB">f&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">A</span><span style="color: #DD0000">"To:&nbsp;rob@akrabat.com"&nbsp;</span><span style="color: #007700">\
|&nbsp;/</span><span style="color: #0000BB">usr</span><span style="color: #007700">/</span><span style="color: #0000BB">sbin</span><span style="color: #007700">/</span><span style="color: #0000BB">sendmail&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">t&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">i
</span>
</span></code></pre>
<p>This script causes all emails to be redirect to my email address with the original to, cc and bcc fields renamed in the headers, so they can be checked!. I like this solution even better than Fakemail as it's easier to see exactly what the mail looks like in a mail client, especially for HTML format.</p>
<p>I just wish I had thought of this script myself! However <a href="http://seancoates.com/mail-replacement----a-better-hack">Sean Coates</a> came up with the idea in 2005 and I've been using it every since. </p>
]]></content:encoded>
			<wfw:commentRss>http://akrabat.com/php/redirecting-email-whilst-developing/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

