<?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>David Caunt</title>
	<atom:link href="http://www.davidcaunt.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davidcaunt.co.uk</link>
	<description>PHP and Zend Framework Engineer</description>
	<lastBuildDate>Sat, 20 Mar 2010 18:53:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Easy command line scripts with Zend Application</title>
		<link>http://www.davidcaunt.co.uk/2010/02/25/easy-command-line-scripts-with-zend-application/</link>
		<comments>http://www.davidcaunt.co.uk/2010/02/25/easy-command-line-scripts-with-zend-application/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 00:46:22 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend-application]]></category>
		<category><![CDATA[zend-framework]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=83</guid>
		<description><![CDATA[As PHP developers, it is convenient to be able to write command line scripts in PHP. In doing so, you will almost certainly want access to Zend Framework components and their configurations as if you are writing a normal MVC app, but without invoking the MVC stack and without loading unnecessary resources. I&#8217;ve seen solutions [...]]]></description>
			<content:encoded><![CDATA[<p>As PHP developers, it is convenient to be able to write command line scripts in PHP. In doing so, you will almost certainly want access to Zend Framework components and their configurations as if you are writing a normal MVC app, but without invoking the MVC stack and without loading unnecessary resources. I&#8217;ve seen solutions where actions are exposed as controller actions and called by wget &#8211; these are counter-intuitive, inefficient, and will suffer from max execution timeouts and other problems.</p>
<h4>Zend_Applicaton to the rescue</h4>
<p>Lets start with our website&#8217;s public/index.php &#8211; the script which sets up and launches an application. It looks roughly like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Define path to application directory</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #339933;">,</span>
              <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../application'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Define application environment</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #339933;">,</span>
              <span style="color: #009900;">&#40;</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span>
                                         <span style="color: #339933;">:</span> <span style="color: #0000ff;">'production'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Application.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$application</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application<span style="color: #009900;">&#40;</span>
    APPLICATION_ENV<span style="color: #339933;">,</span>
    APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/configs/config.php'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>One feature of <a href="http://framework.zend.com/manual/en/zend.application.theory-of-operation.html">Zend Application</a> is that you can choose to bootstrap only certain resources, rather than all of those referenced in your application config and bootstrap (_init methods.) The following assumes that our script needs to use the database, and send an email.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Define path to application directory</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_PATH'</span><span style="color: #339933;">,</span>
              <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../application'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Define application environment</span>
<span style="color: #990000;">defined</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">||</span> <span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #339933;">,</span>
              <span style="color: #009900;">&#40;</span><span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">getenv</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'APPLICATION_ENV'</span><span style="color: #009900;">&#41;</span>
                                         <span style="color: #339933;">:</span> <span style="color: #0000ff;">'production'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Application.php'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$application</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application<span style="color: #009900;">&#40;</span>
    APPLICATION_ENV<span style="color: #339933;">,</span>
    APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/configs/config.php'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//only load resources we need for script, in this case db and mail</span>
<span style="color: #000088;">$application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mail'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Having bootstrapped the resources, we can retrieve them from the application as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$application</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBootstrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getResource</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'db'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//do something!</span>
<span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchRow</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT * FROM something'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2010/02/25/easy-command-line-scripts-with-zend-application/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Zend Framework Pitfalls Part 2 – Zend_Db Won&#8217;t Use the Query Cache with MySQL</title>
		<link>http://www.davidcaunt.co.uk/2009/11/28/zend-framework-pitfalls-part-2-zend_db-wont-use-the-query-cache-with-mysql/</link>
		<comments>http://www.davidcaunt.co.uk/2009/11/28/zend-framework-pitfalls-part-2-zend_db-wont-use-the-query-cache-with-mysql/#comments</comments>
		<pubDate>Sat, 28 Nov 2009 13:35:26 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[pitfalls]]></category>
		<category><![CDATA[zend-framework]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=74</guid>
		<description><![CDATA[This one&#8217;s not limited to Zend Framework, but is actually a &#8216;problem&#8217; in MySQL. I think it is worth covering, as the paragraph in the manual is easily missed.
From the MySQL manual:
Before MySQL 5.1.17, prepared statements do not use the query cache. Beginning with 5.1.17, prepared statements use the query cache under certain conditions, which [...]]]></description>
			<content:encoded><![CDATA[<p>This one&#8217;s not limited to Zend Framework, but is actually a &#8216;problem&#8217; in MySQL. I think it is worth covering, as the <a href="http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.other-statements" target="_blank">paragraph in the manual</a> is easily missed.</p>
<p>From the MySQL manual:</p>
<blockquote><p>Before MySQL 5.1.17, prepared statements do <em>not </em>use the query cache. Beginning with 5.1.17, prepared statements use the query cache under certain conditions, which differ depending on the preparation method</p></blockquote>
<p>This means that if you&#8217;re running MySQL 5.0.x, not uncommon at the time of writing, your applications are not going to benefit from the query cache. There&#8217;s a simple workaround, however:</p>
<p>If you&#8217;re using Pdo, set the following driver option:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$pdoParams</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    PDO<span style="color: #339933;">::</span><span style="color: #004000;">MYSQL_ATTR_USE_BUFFERED_QUERY</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'host'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'username'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'webuser'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'password'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'xxxxxxxx'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'dbname'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'driver_options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pdoParams</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Zend_Config_Ini [<a href="http://php.net/parse_ini_file" target="_blank">parse_ini_file()</a>] doesn&#8217;t support class constants, so ini users will have to supply the value of PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1000, in their configs:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.db.adapter         <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> pdo_mysql</span>
resources.db.params.host     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> localhost</span>
resources.db.params.username <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> webuser</span>
resources.db.params.password <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> xxxxxxxx</span>
resources.db.params.dbname   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> myDb</span>
resources.db.params.driver_options.1000 <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> true</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2009/11/28/zend-framework-pitfalls-part-2-zend_db-wont-use-the-query-cache-with-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serving gzipped assets from Amazon S3 &amp; Cloudfront</title>
		<link>http://www.davidcaunt.co.uk/2009/10/13/serving-gzipped-assets-from-amazon-s3-and-cloudfront/</link>
		<comments>http://www.davidcaunt.co.uk/2009/10/13/serving-gzipped-assets-from-amazon-s3-and-cloudfront/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 14:58:59 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[cloudfront]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=64</guid>
		<description><![CDATA[One of the first steps in improving front-end performance is to migrate static assets to a content delivery network, such as Amazon&#8217;s CloudFront or Akamai. CloudFront is particularly attractive with its pay-as-you-go model, tiny upfront investment and ease of use.
Your existing web server may already be set up to compress JavaScript and CSS, potentially saving hundreds of kb on [...]]]></description>
			<content:encoded><![CDATA[<p>One of the first steps in improving front-end performance is to migrate static assets to a content delivery network, such as Amazon&#8217;s <a href="http://aws.amazon.com/cloudfront/">CloudFront</a> or <a href="http://www.akamai.com/">Akamai</a>. CloudFront is particularly attractive with its pay-as-you-go model, tiny upfront investment and ease of use.</p>
<p>Your existing web server may already be set up to compress JavaScript and CSS, potentially saving hundreds of kb on the wire. In uploading and testing your assets on CloudFront you&#8217;ll soon realise that it doesn&#8217;t perform any gzipping or compression. How to benefit from Amazon&#8217;s superfast edge locations <em>and </em>smaller file sizes?</p>
<p>When your browser requests a page, the headers sent might look like the following:</p>
<pre>Host: www.davidcaunt.co.uk
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729) FirePHP/0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.8,en-gb;q=0.5,en-us;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.davidcaunt.co.uk/about/</pre>
<p>The header we&#8217;re interested in here is Accept-Encoding &#8211; this denotes whether the browser can cope with gzipped assets, and is used by Apache to decide whether to compress them. We can use this header in our PHP scripts to reference pre-compressed assets, and here&#8217;s how:</p>
<ol>
<li>Compress asset, e.g. home.css -&gt; home.cssgz</li>
<li>Upload both files, home.css and home.cssgz to S3 (CloudFront)</li>
<li>Add PHP code to link to the compressed file if the browser accepts</li>
</ol>
<p>You can easily compress assets on Linux using the following:</p>
<pre>gzip home.css</pre>
<p>In step 2, you&#8217;ll need to inform S3 that your assets are gzipped. S3 allows you to specify headers that will be sent with your file:</p>
<pre>Content-Encoding: gzip</pre>
<p>All good libraries and gui tools will help with this. It also makes sense to set Expires headers, if your assets are versioned.</p>
<p>Then the following PHP snippet should be all you need:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_ACCEPT_ENCODING'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'gzip'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/css/home.cssgz'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/css/home.css'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You&#8217;ll want to integrate this code into your View Helpers (Zend Framework) or application code for generating asset URLs.</p>
<p><strong><span style="text-decoration: underline;">Note</span></strong></p>
<p>You&#8217;ll notice I&#8217;ve named my file home.cssgz, not home.css.gz. I had problems with Safari PC (and probably Mac) refusing to use these files inline, and being disposed as attachments.</p>
<p><span style="text-decoration: underline;"><strong><br />
</strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2009/10/13/serving-gzipped-assets-from-amazon-s3-and-cloudfront/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Framework Pitfalls Part 1 &#8211; Zend_Auth</title>
		<link>http://www.davidcaunt.co.uk/2009/10/12/zend-framework-pitfalls-part-1-zend_auth/</link>
		<comments>http://www.davidcaunt.co.uk/2009/10/12/zend-framework-pitfalls-part-1-zend_auth/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 10:12:17 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[pitfalls]]></category>
		<category><![CDATA[zend-auth]]></category>
		<category><![CDATA[zend-framework]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=51</guid>
		<description><![CDATA[Foreword
Zend Framework is excellent; this series of posts entitled &#8216;Zend Framework Pitfalls&#8217; won&#8217;t try and dispute that. There are, however, one or two problems and poorly implemented components that can cause problems. Before using any library component it is important to be aware of any drawbacks and issues. It is then possible to make an [...]]]></description>
			<content:encoded><![CDATA[<h3>Foreword</h3>
<p>Zend Framework is excellent; this series of posts entitled &#8216;Zend Framework Pitfalls&#8217; won&#8217;t try and dispute that. There are, however, one or two problems and poorly implemented components that can cause problems. Before using any library component it is important to be aware of any drawbacks and issues. It is then possible to make an objective decision before investing your time, and you can avoid banging your head against the desk understanding a known bug or problem that isn&#8217;t well documented.</p>
<h4><strong>Component</strong></h4>
<p><a href="http://framework.zend.com/manual/en/zend.auth.html">Zend_Auth</a></p>
<h4>Priority</h4>
<p>Minor (<a href="http://framework.zend.com/issues/secure/ShowConstantsHelp.jspa?decorator=popup#PriorityLevels" target="_blank">definition</a>)</p>
<h4>Problem</h4>
<p>Zend_Auth is implemented as a <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton</a><strong>. </strong>This singleton references a single instance of Zend_Auth_Storage_Interface, used to persist an identity. This makes management of two or more authentication systems (e.g. frontend and admin) difficult. You must manually set the storage each time you want to query a different identity.</p>
<h4>Solution 1 &#8211; Don&#8217;t use multiple authentication systems</h4>
<p>In most simple web applications, you can use a single user database (table) to store both common users and administrators, and expose administrator privileges as appropriate via Zend_Acl or similar.</p>
<h4>Solution 2 &#8211; Toggle storage</h4>
<p>Zend_Auth has a method for changing storage, setStorage. Calling this method every time before retrieving the identity object is viable, but you have to remember to do so <em>every</em> time or you could read the wrong storage. This can be wrapped up for practicality:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> My_Auth <span style="color: #000000; font-weight: bold;">extends</span> Zend_Auth <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getInstance<span style="color: #009900;">&#40;</span><span style="color: #000088;">$storageNamespace</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Zend_Auth'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// set namespace</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStorage</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Zend_Auth_Storage_Session<span style="color: #009900;">&#40;</span><span style="color: #000088;">$storageNamespace</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Remember to use this getInstance method every time you need to access your auth (and namespace) rather than storing a reference to the Zend_Auth instance.</p>
<h4>Solution 3 &#8211; Your own implementation of Zend_Auth</h4>
<p>Zend_Auth doesn&#8217;t actually do much heavy lifting. You could write something that can take advantage of the other Zend_Auth_* components, without implementing the singleton pattern. This is suggested in the <a href="http://framework.zend.com/manual/en/zend.auth.html#zend.auth.introduction.persistence">reference manual</a>.</p>
<h4>Summary</h4>
<p>It is unlikely that Zend_Auth will be re-architected for the 2.0 release of Zend Framework, the earliest opportunity for a break in backwards compatibility. Whether the singleton pattern is appropriate is debatable and a strongly advantageous alternative solution would be necessary to justify any changes.</p>
<p>As always, your comments and solution suggestions are welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2009/10/12/zend-framework-pitfalls-part-1-zend_auth/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Image proposal accepted</title>
		<link>http://www.davidcaunt.co.uk/2009/10/10/zend-image-proposal-accepted/</link>
		<comments>http://www.davidcaunt.co.uk/2009/10/10/zend-image-proposal-accepted/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 16:04:11 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[zend-framework]]></category>
		<category><![CDATA[zend-image]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=47</guid>
		<description><![CDATA[It&#8217;s official &#8211; Zend have accepted our Zend_Image proposal. Credit goes to Dolf Schimmel for writing the initial proposal and liaising with the Zend team.
Zend_Image will initially support two adapters, Gd and Imagick (ImageMagick), and Gmagick support may be added in future. The following common image operations will be supported:

Resize
Rotate
Watermark
Filtering
Format Conversion (e.g. JPG to PNG)
Drawing [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s official &#8211; Zend have accepted our <a title="Zend Framework Proposal Zend Image" href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Image+-+Dolf+Schimmel" target="_self">Zend_Image proposal</a>. Credit goes to Dolf Schimmel for writing the initial proposal and liaising with the Zend team.</p>
<p>Zend_Image will initially support two adapters, <a href="http://php.net/gd">Gd </a>and <a href="http://php.net/imagick">Imagick</a> (ImageMagick), and <a href="http://uk.php.net/gmagick">Gmagick </a>support may be added in future. The following common image operations will be supported:</p>
<ul>
<li>Resize</li>
<li>Rotate</li>
<li>Watermark</li>
<li>Filtering</li>
<li>Format Conversion (e.g. JPG to PNG)</li>
<li>Drawing (lines, arcs, ellipses, polygon, text)</li>
</ul>
<p>Major benefits of Zend_Image include portability and a uniform API across adaptors. It will also be possible to define custom and composite actions for reuse.</p>
<p>We&#8217;re excited to proceed with development and hoping for inclusion in the forthcoming 1.10 release. We welcome your feedback on the <a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Image+-+Dolf+Schimmel">proposal page</a> if you have ideas or comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2009/10/10/zend-image-proposal-accepted/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Avoiding Firefox &#8217;screen jumping&#8217; when scrollbars are displayed</title>
		<link>http://www.davidcaunt.co.uk/2009/09/15/avoiding-firefox-screen-jumping-when-scrollbars-are-displayed/</link>
		<comments>http://www.davidcaunt.co.uk/2009/09/15/avoiding-firefox-screen-jumping-when-scrollbars-are-displayed/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 12:31:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[ux]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=41</guid>
		<description><![CDATA[I recently discovered a simple way to improve the experience of Firefox users when navigating through a website. When a document is longer than the viewport, Firefox will display a vertical scrollbar, but when the document is shorter the scrollbar is not displayed. Constant toggling of the scrollbar is jarring to users and often gives [...]]]></description>
			<content:encoded><![CDATA[<p>I recently discovered a simple way to improve the experience of Firefox users when navigating through a website. When a document is longer than the viewport, Firefox will display a vertical scrollbar, but when the document is shorter the scrollbar is not displayed. Constant toggling of the scrollbar is jarring to users and often gives the illusion that your pages are not consistently designed.</p>
<p>Fortunately there&#8217;s a fix which means the scrollbar is always displayed. Simply add this to your css:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">html <span style="color: #00AA00;">&#123;</span>
    overflow-y<span style="color: #00AA00;">:</span><span style="color: #993333;">scroll</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2009/09/15/avoiding-firefox-screen-jumping-when-scrollbars-are-displayed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blog Launch</title>
		<link>http://www.davidcaunt.co.uk/2009/08/31/blog-launch/</link>
		<comments>http://www.davidcaunt.co.uk/2009/08/31/blog-launch/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 23:33:05 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.davidcaunt.co.uk/?p=31</guid>
		<description><![CDATA[Hello, and welcome to my blog!
My intention is to write web development articles and tutorials, with a particular focus on Zend Framework and PHP. These are likely to be programming oriented, covering solutions to problems that are not already well documented on the web.
]]></description>
			<content:encoded><![CDATA[<p>Hello, and welcome to my blog!</p>
<p>My intention is to write web development articles and tutorials, with a particular focus on Zend Framework and PHP. These are likely to be programming oriented, covering solutions to problems that are not already well documented on the web.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.davidcaunt.co.uk/2009/08/31/blog-launch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
