<?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>Glen Scott - Keeping it simple &#187; php</title>
	<atom:link href="http://www.glenscott.co.uk/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.glenscott.co.uk/blog</link>
	<description>Thoughts on software development and other geeky pursuits.</description>
	<lastBuildDate>Thu, 02 Feb 2012 11:35:47 +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>Map invoke errors when using MongoDB MapReduce</title>
		<link>http://www.glenscott.co.uk/blog/2012/02/02/map-invoke-errors-when-using-mongodb-mapreduce/</link>
		<comments>http://www.glenscott.co.uk/blog/2012/02/02/map-invoke-errors-when-using-mongodb-mapreduce/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 11:34:33 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[mongodb]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/blog/?p=732</guid>
		<description><![CDATA[When running MapReduce operations on your data, you must make sure that any fields you refer to within your map operation are available for every document in your collection. If you try a map operation and some documents do not have the required field, you will get the following assertion error when running the command: [...]]]></description>
			<content:encoded><![CDATA[<p>When running MapReduce operations on your data, you must make sure that any fields you refer to within your map operation <strong>are available for every document</strong> in your collection.  If you try a map operation and some documents do not have the required field, you will get the following assertion error when running the command:</p>
<pre>map invoke failed: JS Error: TypeError: this.fieldname has no properties</pre>
<p><code>fieldname</code> in this case is a field that does not exist in all of the documents.</p>
<p>To prevent this error, you can pass the optional <code>query</code> parameter to the command to make sure that only documents with this field are queried.  For example, in PHP, add the following to the command operation:</p>
<pre name="code" class="php">

$db->command(
    'mapreduce' => 'collection',
    'map'       => $map,
    'reduce'    => $reduce,
    'out'       => array( 'inline' => 1 ),
    'query'     => array( "fieldname" => array( '$exists' => true, ) )
);
</pre>
<p>This makes sure that MapReduce operations are only run on a subset of the collection.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2012/02/02/map-invoke-errors-when-using-mongodb-mapreduce/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting started with MongoDB and PHP on Mac OS X</title>
		<link>http://www.glenscott.co.uk/blog/2011/10/06/getting-started-with-mongodb-and-php-on-mac-os-x/</link>
		<comments>http://www.glenscott.co.uk/blog/2011/10/06/getting-started-with-mongodb-and-php-on-mac-os-x/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 21:16:18 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/blog/?p=633</guid>
		<description><![CDATA[Introduction MongoDB is a document-orientated database written with scalability and high-performance in mind. It is one of a growing number of NoSQL systems &#8211; a database that does not rely on SQL or relational theory at all. Getting a MongoDB server working with PHP on Mac OS X is relatively straightforward, and this tutorial shows [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/sooey/5745780202/" title="NYã¿ã‚„ã’ã®Mongo goodsè²°ã£ãŸï¼ by junojp, on Flickr"><img src="http://farm3.static.flickr.com/2707/5745780202_154a6256c0.jpg" width="500" height="500" alt="NYã¿ã‚„ã’ã®Mongo goodsè²°ã£ãŸï¼"></a></p>
<h2>Introduction</h2>
<p><a href="http://www.mongodb.org/">MongoDB</a> is a document-orientated database written with scalability and high-performance in mind.  It is one of a growing number of NoSQL systems &#8211; a database that does not rely on SQL or relational theory at all.</p>
<p>Getting a MongoDB server working with PHP on Mac OS X is relatively straightforward, and this tutorial shows you how.</p>
<h2>Installing the MongoDB Server</h2>
<p>The first step requires you to download and install the actual MongoDB system.  The example shown below downloads v2.0.0 64 bit binaries for OS X.  For other binaries, please check out the <a href="http://www.mongodb.org/downloads">MongoDB Downloads</a> page.</p>
<pre class="brush: shell;">
cd /tmp
curl -O http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.0.tgz
tar zxvf mongodb-osx-x86_64-2.0.0.tgz
sudo mv mongodb-osx-x86_64-2.0.0 /usr/local/mongodb
mkdir /usr/local/mongodb/data
</pre>
<h2>Configuring the MongoDB server</h2>
<p>We need to create a small configuration file so that MongoDB knows where its data files reside.  Create the file <code>/usr/local/mongodb/mongod.conf</code> and add the following line:</p>
<pre class="brush: shell;">
dbpath = /usr/local/mongodb/data
</pre>
<h2>Starting MongoDB</h2>
<p>To manually start the MongoDB server, use the following command:</p>
<pre class="brush: shell;">
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongod.conf
</pre>
<p>This will start the server and will by default log all output to STDOUT.</p>
<h2>Installing the MongoDB PHP Extension</h2>
<p>Installing the PHP extension is simple:</p>
<pre class="brush: shell;">
sudo pecl install mongo
</pre>
<p>Once this has completed, add the following line to your <code>/etc/php.ini</code> file:</p>
<pre class="brush: shell;">
extension=mongo.so
</pre>
<p>Restart apache using <code>sudo apachectl restart</code>, and the extension should be available.  This can be verified with the <code>phpinfo</code> call:</p>
<p><img src="/images/mongo-php.png" width="600" height="372" alt="MongoDB extension for PHP" /></p>
<h2>Example PHP script</h2>
<p>To test your setup, the following simple script can be used to create a new collection and add two new records:</p>
<pre name="code" class="php">
    &lt;?php

    // connect
    $m = new Mongo();

    // select a database
    $db = $m->comedy;

    // select a collection (analogous to a relational database's table)
    $collection = $db->cartoons;

    // add a record
    $obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" );
    $collection->insert($obj);

    // add another record, with a different "shape"
    $obj = array( "title" => "XKCD", "online" => true );
    $collection->insert($obj);

    // find everything in the collection
    $cursor = $collection->find();

    // iterate through the results
    foreach ($cursor as $obj) {
        echo $obj["title"] . "\n";
    }

    ?&gt;
</pre>
<p>The script should output the following:</p>
<pre>
Calvin and Hobbes
XKCD
</pre>
<p>And that&#8217;s it!  You now have a working MongoDB setup on Mac OS X.</p>
<p>For more information on the PHP extension for MongoDB, please see the following pages in the PHP Manual:</p>
<p><a href="http://php.net/manual/en/book.mongo.php">PHP: Mongo &#8211; Manual</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2011/10/06/getting-started-with-mongodb-and-php-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install mcrypt PHP extension on Mac OS X Lion</title>
		<link>http://www.glenscott.co.uk/blog/2011/08/29/install-mcrypt-php-extension-on-mac-os-x-lion/</link>
		<comments>http://www.glenscott.co.uk/blog/2011/08/29/install-mcrypt-php-extension-on-mac-os-x-lion/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 18:55:21 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mcrypt]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/blog/?p=523</guid>
		<description><![CDATA[If you have a need to install the mcrypt extension for PHP, for example if you need to use phpMyAdmin, then these instructions are for you. Thankfully, it is becoming simpler to install PHP extensions than with previous versions of OS X. Xcode The Xcode package installs the necessary versions of tools like autoconf which [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a need to install the <a href="http://www.php.net/manual/en/book.mcrypt.php">mcrypt extension for PHP</a>, for example if you need to use <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, then these instructions are for you.</p>
<p>Thankfully, it is becoming simpler to install PHP extensions than with previous versions of OS X.  </p>
<h3>Xcode</h3>
<p>The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process. Make sure you have at least Xcode v4.1 installed; the install package (&#8220;Install Xcode&#8221;) is available in your &#8220;Applications&#8221; folder.</p>
<h3>libmcrypt</h3>
<p><a href="http://www.sourceforge.net/projects/mcrypt">libmcrypt</a> is the library that provides the encryption functions.  We need to install this before building the PHP extension.</p>
<ul>
<li>Open up Terminal.app</li>
<li>Download <a href="http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/">libmcrypt from sourceforge</a></li>
<li>Unpack the archive somewhere</li>
<li><code>cd libmcrypt</code></li>
<li><code>./configure</code></li>
<li><code>make</code></li>
<li><code>sudo make install</code></li>
</ul>
<h3>PHP Extension</h3>
<p>Once we have libmcrypt installed, we can build the PHP extension.</p>
<ul>
<li><a href="http://museum.php.net/php5/php-5.3.6.tar.bz2">Download PHP 5.3.6 source</a></li>
<li>Unpack the archive and <code>cd php-5.3.6/ext/mcrypt/</code></li>
<li>phpize</li>
</ul>
<p>You should see output similar to the following:</p>
<pre>
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
</pre>
<ul>
<li><code>./configure</code></li>
<li><code>make</code></li>
<li><code>sudo make install</code></li>
</ul>
<p>On successful install, you will see the following message:</p>
<pre>
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/
</pre>
<p>To enable the module, include the following line in your <code>/etc/php.ini</code> file:</p>
<pre>
extension = mcrypt.so
</pre>
<p>Finally, restart your Apache server:</p>
<pre>
sudo apachectl restart
</pre>
<p>And that&#8217;s it:  you should now be able to utilise the functions, as detailed in the <a href="http://uk3.php.net/mcrypt">PHP mcrypt documentation</a>.</p>
<p><a href="/images/mcrypt-106.png"><img src="/images/mcrypt-106-m.png" alt="mcrypt php extension"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2011/08/29/install-mcrypt-php-extension-on-mac-os-x-lion/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Mac OS X Lion PHP upgrade &#8211; php.ini and Suhosin</title>
		<link>http://www.glenscott.co.uk/blog/2011/07/29/mac-os-x-lion-php-upgrade-php-ini-and-suhosin/</link>
		<comments>http://www.glenscott.co.uk/blog/2011/07/29/mac-os-x-lion-php-upgrade-php-ini-and-suhosin/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 10:58:57 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/blog/?p=517</guid>
		<description><![CDATA[If you have upgraded from Snow Leopard to the new OS X Lion, you will notice PHP has also been upgraded &#8211; from 5.2 to 5.3. A couple of points that I noticed post-install. Firstly, my existing /etc/php.ini file was moved to /etc/php.ini-5.2-previous. Restoring this was trivial: sudo cp /etc/php.ini-5.2-previous /etc/php.ini However, I noticed that [...]]]></description>
			<content:encoded><![CDATA[<p>If you have upgraded from Snow Leopard to the new OS X Lion, you will notice PHP has also been upgraded &#8211; from 5.2 to 5.3.</p>
<p>A couple of points that I noticed post-install.  Firstly, my existing <code>/etc/php.ini</code> file was moved to <code>/etc/php.ini-5.2-previous</code>.  Restoring this was trivial:</p>
<p><code>sudo cp /etc/php.ini-5.2-previous /etc/php.ini<br />
</code></p>
<p>However, I noticed that extensions previously installed under <code>/usr/lib/php/extensions/no-debug-non-zts-20090626/</code> had been removed.  So, if you have extensions that you wish to still use with 5.3, they will need to be re-built.</p>
<p>I also noticed that Apple have included the Suhosin patch and extension.  Suhosin is part of the <a href="http://www.hardened-php.net/">Hardened-PHP</a> project which aims to protect PHP applications against buffer-overflow and format string vulnerabilities.  In theory, this functionality should be transparent to your application &#8211; no configuration or code changes are required.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2011/07/29/mac-os-x-lion-php-upgrade-php-ini-and-suhosin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install mcrypt PHP extension on OS X Snow Leopard</title>
		<link>http://www.glenscott.co.uk/blog/2011/02/03/install-mcrypt-php-extension-on-os-x-snow-leopard/</link>
		<comments>http://www.glenscott.co.uk/blog/2011/02/03/install-mcrypt-php-extension-on-os-x-snow-leopard/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 23:08:22 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/blog/?p=508</guid>
		<description><![CDATA[Please note: The following instructions apply to Mac OS X 10.6 (Snow Leopard). I have an updated guide for how to install mcrypt on 10.7 (Lion). mcrypt is a useful extension to PHP if you would like to support a wide range of encryption algorithms within your code. This guide explains how you can enable [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/ev0luti0nary/5269693629/" title="Lock away the evil... by Ev0luti0nary, on Flickr"><img src="http://farm6.static.flickr.com/5128/5269693629_897ed25803.jpg" width="500" height="332" alt="Lock away the evil..."></a></p>
<p><em>Please note:  The following instructions apply to Mac OS X 10.6 (Snow Leopard).  I have an updated guide for how to <a href="http://www.glenscott.co.uk/blog/2011/08/29/install-mcrypt-php-extension-on-mac-os-x-lion/">install mcrypt on 10.7 (Lion)</a>.</em></p>
<p><a href="http://mcrypt.sourceforge.net/">mcrypt</a> is a useful extension to PHP if you would like to support a wide range of encryption algorithms within your code.</p>
<p>This guide explains how you can enable install mcrypt, along with the PHP extension, on Mac OS X 10.6.</p>
<h3>Xcode</h3>
<p>The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process. Make sure you have at least Xcode v3.2 installed; the install package is available on the Snow Leopard install DVD under the â€œOptional Installsâ€ folder.</p>
<h3>libmcrypt</h3>
<p><a href="http://www.sourceforge.net/projects/mcrypt">libmcrypt</a> is the library that provides the encryption functions.  We need to install this before building the PHP extension.</p>
<ul>
<li>Open up Terminal.app</li>
<li><code>export CFLAGS="-arch x86_64"</code></li>
<li>Download <a href="http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/">libmcrypt from sourceforge</a></li>
<li>Unpack the archive somewhere</li>
<li><code>cd libmcrypt</code></li>
<li><code>./configure --disable-shared</code></li>
<li><code>make</code></li>
<li><code>sudo make install</code></li>
</ul>
<h3>PHP Extension</h3>
<p>Once we have libmcrypt installed, we can build the PHP extension.</p>
<ul>
<li><a href="http://museum.php.net/php5/php-5.3.4.tar.gz">Download PHP 5.3.4 source (tar gz format)</a></li>
<li>Unpack the archive and <code>cd php-5.3.4/ext/mcrypt/</code></li>
<li>phpize</li>
</ul>
<p>You should see output similar to the following:</p>
<pre>
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
</pre>
<ul>
<li><code>./configure</code></li>
<li><code>make</code></li>
<li><code>sudo make install</code></li>
</ul>
<p>On successful install, you will see the following message:</p>
<pre>
Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/
</pre>
<p>To enable the module, include the following line in your <code>/etc/php.ini</code> file:</p>
<pre>
extension = mcrypt.so
</pre>
<p>Finally, restart your Apache server:</p>
<pre>
sudo apachectl restart
</pre>
<p>And that&#8217;s it:  you should now be able to utilise the functions, as detailed in the <a href="http://uk3.php.net/mcrypt">PHP mcrypt documentation</a>.</p>
<p><a href="/images/mcrypt-106.png"><img src="/images/mcrypt-106-m.png" alt="mcrypt php extension"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2011/02/03/install-mcrypt-php-extension-on-os-x-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Normalize URL&#8217;s with PHP</title>
		<link>http://www.glenscott.co.uk/blog/2011/01/09/normalize-urls-with-php/</link>
		<comments>http://www.glenscott.co.uk/blog/2011/01/09/normalize-urls-with-php/#comments</comments>
		<pubDate>Sun, 09 Jan 2011 18:29:40 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/blog/?p=497</guid>
		<description><![CDATA[I&#8217;ve posted to GitHub a PHP class that I&#8217;ve written which can handle URL normalization, as specified by RFC 3986. https://github.com/glenscott/url-normalizer Specifically, the following normalization steps are performed: Normalize case Decode unreserved characters Remove dot segments An example of use: require_once 'URLNormalizer.php'; $url = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d'; $un = new URLNormalizer(); $un->setUrl( $url ); echo $un->normalize(); // [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve posted to GitHub a PHP class that I&#8217;ve written which can handle URL normalization, as specified by <a href="http://www.apps.ietf.org/rfc/rfc3986.html">RFC 3986</a>.</p>
<p><a href="https://github.com/glenscott/url-normalizer">https://github.com/glenscott/url-normalizer</a></p>
<p>Specifically, the following normalization steps are performed:</p>
<ol>
<li>Normalize case</li>
<li>Decode unreserved characters</li>
<li>Remove dot segments</li>
</ol>
<p>An example of use:</p>
<pre name="code" class="php">
require_once 'URLNormalizer.php';

$url = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d';
$un = new URLNormalizer();
$un->setUrl( $url );
echo $un->normalize();

// result: "example://a/b/c/%7Bfoo%7D"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2011/01/09/normalize-urls-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Install memcached PHP extension on OS X Snow Leopard</title>
		<link>http://www.glenscott.co.uk/blog/2009/08/30/install-memcached-php-extension-on-os-x-snow-leopard/</link>
		<comments>http://www.glenscott.co.uk/blog/2009/08/30/install-memcached-php-extension-on-os-x-snow-leopard/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 15:54:21 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[memcached]]></category>
		<category><![CDATA[pecl]]></category>
		<category><![CDATA[snowleopard]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/?p=424</guid>
		<description><![CDATA[memcached is a very useful memory object caching system, which can be used to increase the performance of your dynamic scripts by caching database calls. This guide will explain how to install the memcached system, including the PHP extension, on Mac OS X 10.6. Xcode The Xcode package installs the necessary versions of tools like [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/chrissinjo/5368405044/" title="Memories by ChrisSinjo, on Flickr"><img src="http://farm6.static.flickr.com/5089/5368405044_c49ce38414.jpg" width="500" height="334" alt="Memories"></a></p>
<p><a href="http://www.danga.com/memcached/">memcached</a> is a very useful memory object caching system, which can be used to increase the performance of your dynamic scripts by caching database calls.</p>
<p>This guide will explain how to install the memcached system, including the PHP extension, on Mac OS X 10.6.</p>
<h2>Xcode</h2>
<p>The Xcode package installs the necessary versions of tools like autoconf which is needed during the PHP extension compilation process.  Make sure you have Xcode 3.2 installed;  the install package is available on the Snow Leopard install DVD under the &#8220;Optional Installs&#8221; folder.</p>
<h2>libevent</h2>
<p><a href="http://www.monkey.org/~provos/libevent/">libevent</a> is a pre-requisite for memcached.</p>
<ul>
<li><code>cd /tmp; curl -O http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz</code></li>
<li><code>tar zxvf libevent-1.4.12-stable.tar.gz</code></li>
<li><code>cd libevent-1.4.12-stable</code></li>
<li><code>./configure; make</code></li>
<li><code>sudo make install</code></li>
</ul>
<h2>memcached</h2>
<p><a href="http://www.danga.com/memcached/download.bml">memcached</a> is the daemon responsible for actually storing and retrieving arbitrary objects for your applications.</p>
<ul>
<li><code>cd /tmp; curl -O http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz</code></li>
<li><code>tar zxvf memcached-1.4.1.tar.gz</code></li>
<li><code>cd  memcached-1.4.1</code></li>
<li><code>./configure; make</code></li>
<li><code>sudo make install</code></li>
</ul>
<h2>libmemcached</h2>
<p><a href="http://freshmeat.net/projects/libmemcached">libmemcached</a> is the shared library that will allow clients, in this case PHP, access the memcached daemon.</p>
<ul>
<li>Download libmemcached, move to <code>/tmp</code> and unpack</li>
<li><code>cd libmemcached-0.31</code></li>
<li><code>./configure; make</code></li>
<li><code>sudo make install</code></li>
</ul>
<h2>php extension</h2>
<p>Now we are ready to prepare the PHP extension to memcached, which is available from <a href="http://pecl.php.net">pecl</a>.</p>
<ul>
<li><code>cd /tmp; pecl download memcached</code></li>
<li><code>gzip -d < memcached-1.0.0.tgz | tar -xvf -</code></li>
<li><code>cd memcached-1.0.0; phpize</code></li>
</ul>
<p>You should see output similar to the following:<br />
<code><br />
Configuring for:<br />
PHP Api Version:         20090626<br />
Zend Module Api No:      20090626<br />
Zend Extension Api No:   220090626<br />
</code></p>
<ul>
<li><code>./configure; make</code></li>
<li><code>sudo make install</code></li>
</ul>
<p>On a successful install, you will get the following message:</p>
<p><code>Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20090626/</code></p>
<p>Modify your <code>php.ini</code> configuration file and make sure you have the following line included:</p>
<p><code>extension = memcached.so</code></p>
<p>You can then restart your Apache server:</p>
<ul>
<li><code>sudo apachectl restart</code></li>
</ul>
<p>to make the memcached functionality available in your scripts.</p>
<p><a href="/images/memcached-php.png"><img src="/images/memcached-php-med.png" width="450" height="140" alt="memcached php extension" border="0"></a></p>
<h2>References</h2>
<ul>
<li><a href="http://php.net/manual/en/install.pecl.phpize.php">Compiling shared PECL extensions with phpize</a></li>
<li><a href="http://php.net/memcached">PHP: Memcached - Manual</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2009/08/30/install-memcached-php-extension-on-os-x-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Fix PHP timezone warnings in OS X Snow Leopard</title>
		<link>http://www.glenscott.co.uk/blog/2009/08/30/fix-php-timezone-warnings-in-os-x-snow-leopard/</link>
		<comments>http://www.glenscott.co.uk/blog/2009/08/30/fix-php-timezone-warnings-in-os-x-snow-leopard/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 09:07:30 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[snowleopard]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/?p=417</guid>
		<description><![CDATA[The standard Mac install of PHP has always been somewhat quirky, and 10.6 is no exception. One of the most obvious issues occurs when attempting to use date/time functions. PHP 5.3 requires that the date.timezone setting is available. Without this, you will receive a warning similar to the following: Warning: getdate() [function.getdate]: It is not [...]]]></description>
			<content:encoded><![CDATA[<p>The standard Mac install of PHP has always been somewhat quirky, and 10.6 is no exception.  One of the most obvious issues occurs when attempting to use <a href="http://php.net/manual/en/ref.datetime.php">date/time functions</a>.  PHP 5.3 requires that the <a href="http://php.net/manual/en/datetime.configuration.php#ini.date.timezone">date.timezone</a> setting is available.  Without this, you will receive a warning similar to the following:</p>
<p><code>Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /Users/gscott/Sites/hello-world.php on line 9</code></p>
<p>The solution is to edit (or create, if it doesn&#8217;t exist) <code>/private/etc/php.ini</code> and make sure a setting exists for <code>date.timezone</code>.  For example:</p>
<p>    date.timezone = Europe/London</p>
<p>After making the change, restart Apache</p>
<p>    sudo apachectl restart</p>
<ul>
<li><a href="http://php.net/manual/en/timezones.php">List of supported timezones</a>.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2009/08/30/fix-php-timezone-warnings-in-os-x-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP 5.3: The Good, the Bad and the Ugly</title>
		<link>http://www.glenscott.co.uk/blog/2009/06/30/php-53-the-good-the-bad-and-the-ugly/</link>
		<comments>http://www.glenscott.co.uk/blog/2009/06/30/php-53-the-good-the-bad-and-the-ugly/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 21:55:20 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/?p=405</guid>
		<description><![CDATA[PHP 5.3 was released today; here are my positive and negatives: The Good: Closures Anonymous functions created with create_function have always been a bit messy. With 5.3 comes support for closures with a much cleaner syntax: $greet = function($name) { printf("Hello %s\r\n", $name); }; $greet('World'); $greet('PHP'); The Bad: Backwards incompatible changes Although not a massive [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://php.net/releases/5_3_0.php">PHP 5.3</a> was released today;  here are my positive and negatives:</p>
<h3>The Good:  Closures</h3>
<p>Anonymous functions created with <a href="http://php.net/create_function">create_function</a> have always been a bit messy.  With 5.3 comes support for closures with a much cleaner syntax:</p>
<pre name="code" class="php">
    $greet = function($name)
    {
        printf("Hello %s\r\n", $name);
    };

    $greet('World');
    $greet('PHP');
</pre>
<h3>The Bad:  Backwards incompatible changes</h3>
<p>Although not a massive change from 5.2, there are enough <a href="http://php.net/manual/en/migration53.incompatible.php">differences to break existing code</a>.</p>
<h3>The Ugly:  Namespaces</h3>
<p>There has been <a href="http://blog.fedecarg.com/2008/10/28/php-namespaces-controversy/">quite a discussion</a> about PHP&#8217;s new namespace syntax.  </p>
<pre name="code" class="php">$c = new \my\name\MyClass;</pre>
<p>It&#8217;s just damn ugly.  The more sensible choice, <code>::</code> is already used as the <a href="http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php">scope resolution operator</a> and was therefore dismissed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2009/06/30/php-53-the-good-the-bad-and-the-ugly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mcrypt support for PHP on 64 bit Mac OS X 10.5</title>
		<link>http://www.glenscott.co.uk/blog/2009/03/16/mcrypt-support-for-php-on-64-bit-mac-os-x-105/</link>
		<comments>http://www.glenscott.co.uk/blog/2009/03/16/mcrypt-support-for-php-on-64-bit-mac-os-x-105/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 20:31:28 +0000</pubDate>
		<dc:creator>Glen</dc:creator>
				<category><![CDATA[mac]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[64bit]]></category>
		<category><![CDATA[mcrypt]]></category>

		<guid isPermaLink="false">http://www.glenscott.co.uk/?p=389</guid>
		<description><![CDATA[Please note: The article below refers to installing mcrypt on Mac OS X 10.5. If you have 10.6 Snow Leopard, please see my updated guide: Install mcrypt PHP extension on OS X Snow Leopard Adding additional functionality to the standard Apple-supplied PHP on Mac OS X 10.5 is a little tricky if you are running [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Please note:  The article below refers to installing mcrypt on Mac OS X 10.5.  If you have 10.6 Snow Leopard, please see my updated guide:  <a href="/blog/2011/02/03/install-mcrypt-php-extension-on-os-x-snow-leopard/">Install mcrypt PHP extension on OS X Snow Leopard</a></strong></p>
<p>Adding additional functionality to the standard Apple-supplied PHP on Mac OS X 10.5 is a little tricky if you are running a 64 bit processor such as the Intel Core 2 Duo.  The reason is that any dynamic extensions that you add will need to be 64 bit, and many shared libraries by default will compile as 32 bit binaries.  Trying to use a 32 bit extension with a 64 bit PHP results in the following unfriendly error message:</p>
<p><code>PHP Warning:  PHP Startup: Unable to load dynamic library './mcrypt.so' - (null) in Unknown on line 0</code></p>
<p><a href="http://php.net/mcrypt">mcrypt</a> is a good example of a useful extension that can be added to PHP with a little bit of effort:</p>
<ul>
<li>Open up your Terminal.app</li>
<li>To explicitly build for 64 bit architecture <code>export CFLAGS="-arch x86_64"</code></li>
<li>Download libmcrypt from sourceforge <a href="http://sourceforge.net/projects/mcrypt">http://sourceforge.net/projects/mcrypt</a></li>
<li>Unpack the archive</li>
<li><code>cd libmcrypt</code></li>
<li><code>./configure --disable-shared</code></li>
<li><code>make</code></li>
<li><code>sudo make install</code></li>
<li>download PHP 5.2.6 source from <a href=" http://www.php.net/get/php-5.2.6.tar.bz2/from/a/mirror">http://www.php.net/get/php-5.2.6.tar.bz2/from/a/mirror</a></li>
<li>unpack the archive and go into the <code>php-5.2.6/ext/mcrypt/</code> dir</li>
<li><code>phpize</code></li>
<li><code>./configure</code></li>
<li><code>make</code></li>
<li><code>sudo make install</code></li>
<li>verify the extension is 64 bit: <code>file /usr/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so</code></li>
</ul>
<p><code>/usr/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so: Mach-O 64-bit bundle x86_64</code></p>
<p>To actually use the extension, you can simply create a symbolic link to it.  For example:</p>
<ul>
<li><code>cd ~/Sites</code></li>
<li><code>ln -s  /usr/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so</code></li>
</ul>
<h3>Example code:  mcrypt.php</h3>
<p>Drop the following code into your <code>~/Sites</code> directory to verify everything is working:</p>
<pre name="code" class="php">
    &lt;?php

    if ( ! extension_loaded('mcrypt') ) {
        dl('mcrypt.so');
    }

    $key   = "this is a secret key";
    $input = "Let us meet at 9 o'clock at the secret place.";

    $td = mcrypt_module_open('tripledes', '', 'ecb', '');
    $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
    mcrypt_generic_init($td, $key, $iv);
    $encrypted_data = mcrypt_generic($td, $input);
    mcrypt_generic_deinit($td);
    mcrypt_module_close($td);

    print_r($encrypted_data);

    ?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.glenscott.co.uk/blog/2009/03/16/mcrypt-support-for-php-on-64-bit-mac-os-x-105/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

