<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
  <channel>
    <title>Blog entries tagged pear :: mwop.net</title>
    <description>Blog entries tagged pear :: mwop.net</description>
    <pubDate>Sat, 21 Aug 2010 18:37:14 -0500</pubDate>
    <generator>Laminas_Feed_Writer 2 (https://getlaminas.org)</generator>
    <link>https://mwop.net/blog/tag/pear</link>
    <atom:link rel="self" type="application/rss+xml" href="https://mwop.net/blog/tag/pear/rss.xml"/>
    <item>
      <title>Autoloading Benchmarks</title>
      <pubDate>Sat, 21 Aug 2010 18:37:14 -0500</pubDate>
      <link>https://mwop.net/blog/245-Autoloading-Benchmarks.html</link>
      <guid>https://mwop.net/blog/245-Autoloading-Benchmarks.html</guid>
      <author>contact@mwop.net (Matthew Weier O'Phinney)</author>
      <dc:creator>Matthew Weier O'Phinney</dc:creator>
      <content:encoded><![CDATA[<p>During the past week, I've been looking at different strategies for
<a href="http://php.net/autoload">autoloading</a> in <a href="http://framework.zend.com/">Zend Framework</a>.
I've suspected for some time that our class loading strategy might be one source
of performance degradation, and wanted to research some different approaches,
and compare performance.</p>
<p>In this post, I'll outline the approaches I've tried, the benchmarking stategy I
applied, and the results of benchmarking each approach.</p>


<h2>Autoloading Strategies</h2>
<p>I'm grouping strategies into two categories, PEAR/PSR-0 strategies, and classmap strategies.</p>
<p>I also started testing a third category. This included solutions that required
PECL extensions, specifically the
<a href="http://github.com/metagoto/splclassloader">SplClassLoader</a> and
<a href="http://pecl.php.net/package/automap">Automap</a> extensions. However, I ultimately
abandoned these solutions. In the case of <code>SplClassLoader</code>, I actually started
testing it, but immediately ran into segfaults. This unfortunate event made me
remember that I was looking for userland autoloaders that we could use within
Zend Framework; both <code>SplClassLoader</code> and <code>Automap</code> can be dropped in by users
at any point, but due to the requirement of compiling and installing for your
platform, could never be an explicit requirement for using Zend Framework.</p>
<h3>PEAR/PSR-0</h3>
<p>Those of you familiar with Zend Framework are aware that we follow
<a href="http://pear.php.net/manual/en/coding-standards.php">PEAR Coding Standards</a>,
and, specific to this exercise, their 1-class-1-file naming convention. The PEAR
naming conventions dictate a 1:1 relation between the filesystem and the class.
As an example, the class <code>Foo_Bar_Baz</code> would be found in the file
<code>Foo/Bar/Baz.php</code> on your <code>include_path</code>.</p>
<p>This is a trivially easy convention to remember, and has been widely adopted in
the PHP world. The one and only vote the PHP Framework Interoperability Group
has held so far,
<a href="PSR-0.html">http://groups.google.com/group/php-standards/web/psr-0-final-proposal</a>,
has simply ratified this standard going forward (with some additional verbiage
regarding namespaces). Zend Framework's autoloader has been PSR-0 compliant
since 1.10.0 (and was PEAR-compliant prior to that).</p>
<p>So, the very first approach has been simply to use the <em>status quo</em>.</p>
<p>That said, I also looked at other PSR-0-compliant approaches for some
inspiration. The <code>SplClassLoader</code> proposed by Jon Wage, of the Doctrine project,
as a <a href="http://gist.github.com/221634">GitHub gist</a> takes a couple of departures
from the ZF implementation:</p>
<ul>
<li>It allows specifying a specific directory under which to look for a specific
namespace.</li>
<li>Instead of acting as a singleton, you create a single instance per namespace
you want to load, and then call its <code>register()</code> method to register with the
<code>spl_autoload</code> registry.</li>
</ul>
<p>Additionally, I looked at the Symfony2 <code>UniversalClassLoader</code>. While it has its
basis in the <code>SplClassLoader</code> implementation, it offers a feature we'd already
added to the ZF2 autoloader: the ability to register both namespaces and vendor
prefixes to autoload. I <a href="http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/Psr0Autoloader.php">combined these ideas into a custom PSR-0 implementation</a>.</p>
<p>(Note: the <code>SplClassLoader</code> extension is a literal port of the class from the
<code>GitHub</code> gist to a C extension.)</p>
<h3>Classmaps</h3>
<p>The next category of autoloader solutions I looked at are best characterized by
the term &quot;classmaps.&quot; In this strategy, you create a map of classname/filename
pairs, and feed it to your autoloader.</p>
<p>To my thinking, the key benefits of this strategy include:</p>
<ul>
<li>Ability to deviate from the PSR-0 standard if desired (as an example, application resources).</li>
<li>Ability to drop in a classmap per component. For a library such as ZF, this
opens up possibilities for distributing individual components with fewer
dependencies, as you do not need to also ship artifacts such as your
autoloader.</li>
<li>Fail early. If the class does not exist in the map, the autoloader can exit
early, allowing you to drop to another autoloader in the chain — or simply
have PHP raise its <code>E_FATAL</code> report of class-not-found.</li>
<li>Drop in at will. You can use dynamic autoloaders during development, but then
run a script during deployment or build time to generate a classmap
autoloader. This allows you to have the benefits of a RAD cycle, while also
reaping the benefits of a performance-optimized autoloader.</li>
</ul>
<p>I will elaborate on the last point later, when I examine the benchmarks.</p>
<p>Despite the prevalence of PSR-0 style autoloaders, there are a number of
classmap autoloaders in the wild. <a href="http://incubator.apache.org/zetacomponents/">ez/zeta components</a>
has used one for years, in part due to using a non-PSR-0-compliant naming
convention, but also in part due to performance considerations.
<a href="http://www.google.com/search?q=arne+blankerts">Arne Blankerts</a> also introduced
me to one such solution in the form of his
<a href="http://github.com/theseer/Autoload">Autoload library on GitHub</a>.</p>
<p>When building classmaps, you can either build them manually as you develop, or
utilize a script. I like the script-based approach, as it ensures I don't forget
to add items to the map, and because it's something I can run over existing
libraries and then drop in.</p>
<p>When building such a script, the algorithm is quite simple:</p>
<ul>
<li>Recursively scan a filesystem tree</li>
<li>For each PHP file found, scan for interfaces, classes, and abstract classes</li>
<li>For each match, store the fully qualified class name and the file path</li>
</ul>
<p>I <a href="/blog/244-Applying-FilterIterator-to-Directory-Iteration">blogged about my solution</a> to scanning the filesystem tree earlier; an example of the script that consumes the <code>ClassFileLocater</code> class referenced in that blog and generates the actual classmap <a href="http://github.com/weierophinney/zf2/blob/autoloading/bin/zfal.php">can be found in my GitHub account</a>.</p>
<p>I took three different approaches to generating classmaps:</p>
<ul>
<li>Store file paths as relative to the <code>include_path</code></li>
<li>Store file paths using <code>__DIR__</code> to prefix the path</li>
<li>Store file paths using <code>__DIR__</code> to prefix the path, and pass the map directly to a closure registered with <code>spl_autoload</code>.</li>
</ul>
<p>In the first two cases, the map is stored in an array that is returned by the
script. I then pass the map file's location to an autoloader that performs an
<code>include</code> on that file, stores the map (optionally merging with one it already
contains), and then uses that map for class lookups. You <a href="http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/ClassMapAutoloader.php">can find this autoloader on GitHub</a>.</p>
<p>The third case was a trick borrowed from Arne Blankert's Autoload library. I
deviated from his design in a couple of ways. First, Arne was defining the map
as a static member of his closure. Theoretically, this should ensure the map is
defined only once per request. However, in my tests, I discovered that the map
was actually being constructed in memory each and every time the closure was
invoked, and led to a serious degredation in performance. As a result, my
version creates a variable in the local scope which is then passed in to the
closure via a <code>use</code> statement:</p>
<pre><code class="language-php hljs php" data-lang="php"><span class="hljs-keyword">namespace</span> <span class="hljs-title">test</span>;
$_map = <span class="hljs-keyword">array</span>( <span class="hljs-comment">/* ... */</span> );
spl_autoload_register(<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">($class)</span> <span class="hljs-title">use</span> <span class="hljs-params">($_map)</span> </span>{
    <span class="hljs-keyword">if</span> (array_key_exists($class, $_map)) {
        <span class="hljs-keyword">require_once</span> <span class="hljs-keyword">__DIR__</span> . DIRECTORY_SEPARATOR . $_map[$class];
    }
});
</code></pre>
<p>Note the <code>namespace</code> declaration; this allows you to create multiple autoload
class map files without trampling on previously loaded maps.</p>
<h2>Benchmarking Strategy</h2>
<p>Benchmarking autoloading is somewhat difficult; once you've autoloaded a class,
you can't autoload it again. Additionally, libraries tend to have a finite
number of classes in them, giving a limited set of data to benchmark against.
Finally, no good autoloading benchmark should be done without also testing
against an opcode cache — and if you have too many class files, you can easily
defeat the cache.</p>
<p>My solution was twofold:</p>
<ul>
<li>Create a script to generate finite, large numbers of class files</li>
<li>Determine how many class files provide a reasonable set such that an opcode cache is not defeated, but also such that measurable differences may be observed.</li>
</ul>
<p>The script for generating class files was easy to create. All I needed was a
recursive function that would iterate through the letters of the alphabet and
generate classes until a specific depth was reached;
<a href="http://github.com/weierophinney/zf2/blob/autoloading/bin/createAutoloadTestClasses.php">you can examine the script on GitHub</a>.</p>
<p>I started off by looking at <code>26^3</code> class files, and this was excellent for
getting some initial statistics. However, once I started benchmarking against an
opcode cache, I discovered that I was defeating both the realpath cache as well
as memory limits for my opcode cache. I then reduced my sampling size to <code>16^3</code>
files. This sampling size proved to be sufficiently large to both produce
reliable results on multiple runs while allowing caching to work normally.</p>
<p>When benchmarking, I ran the following strategies:</p>
<ul>
<li>Baseline: no autoloader (all <code>class_exists()</code> calls fail)</li>
<li>ZF1 autoloader (PSR-0 compliant, uses <code>include_path</code>)</li>
<li>PSR-0 autoloader (uses explicit namespace/path pairs, no <code>include_path</code></li>
<li><code>ClassMapAutoloader</code> (using <code>include_path</code>)</li>
<li><code>ClassMapAutoloader</code> (using <code>__DIR__</code>-prefixed paths)</li>
<li>Class map using <code>__DIR__</code>-prefixed paths, with closure registered directly to <code>spl_autoload</code></li>
</ul>
<p>My test algorithm was as follows:</p>
<ul>
<li>Load a list of all classes in the tree</li>
<li>Perform any setup necessary to prepare the given autoloader</li>
<li>Iterate over all classes in the list, and utilize <code>class_exists</code> to autoload</li>
</ul>
<p>Timing was performed only over the loop. Benchmarks were run 10 times for each
strategy, in order to determine an average, as well as to correct for outliers.
Additionally, the benchmarks were performed both with and without bytecode
caching, to see what differences might occur in both environments. A sample of
such a script is as follows:</p>
<pre><code class="language-php hljs php" data-lang="php"><span class="hljs-keyword">include</span> <span class="hljs-string">'benchenv.php'</span>;
<span class="hljs-keyword">require_once</span> <span class="hljs-string">'/path/to/zf/library/Zend/Loader/ClassMapAutoloader.php'</span>;

$loader = <span class="hljs-keyword">new</span> Zend\Loader\ClassMapAutoloader();
$loader-&gt;registerAutoloadMap(<span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/test/map_abs_autoload.php'</span>);
$loader-&gt;register();

<span class="hljs-keyword">echo</span> <span class="hljs-string">"Starting benchmark of ClassFile map autoloader using absolute paths...\n"</span>;
$start = microtime(<span class="hljs-keyword">true</span>);
<span class="hljs-keyword">foreach</span> ($classes <span class="hljs-keyword">as</span> $class) {
    <span class="hljs-keyword">if</span> (!class_exists($class)) {
        <span class="hljs-keyword">echo</span> <span class="hljs-string">"Aborting test; could not find class $class\n"</span>;
        <span class="hljs-keyword">exit</span>(<span class="hljs-number">2</span>);
    }
}
$end = microtime(<span class="hljs-keyword">true</span>);
<span class="hljs-keyword">echo</span> <span class="hljs-string">"total time: "</span> . ($end - $start) . <span class="hljs-string">"s\n"</span>;
</code></pre>
<p>I had one such script for each test case. To automate running all such scripts,
and doing 10 iterations of each, I wrote the following scripts:</p>
<pre><code class="language-bash hljs bash" data-lang="bash"><span class="hljs-meta">#!/usr/bin/zsh</span>
<span class="hljs-comment"># benchmark_noaccel.sh</span>
<span class="hljs-comment"># No opcode caching</span>
<span class="hljs-keyword">for</span> TYPE <span class="hljs-keyword">in</span> baseline.php classmap_abs.php classmap_inc.php spl_autoload.php psr0_autoload.php zf1_autoload.php;<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Starting <span class="hljs-variable">$TYPE</span>"</span>
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> {1..10};<span class="hljs-keyword">do</span>
        curl http://autoloadbench/<span class="hljs-variable">$TYPE</span>
    <span class="hljs-keyword">done</span>
<span class="hljs-keyword">done</span>

<span class="hljs-meta">#!/usr/bin/zsh</span>
<span class="hljs-comment"># benchmark_accel.sh</span>
<span class="hljs-comment"># With opcode caching</span>
<span class="hljs-keyword">for</span> TYPE <span class="hljs-keyword">in</span> baseline.php classmap_abs.php classmap_inc.php spl_autoload.php psr0_autoload.php zf1_autoload.php;<span class="hljs-keyword">do</span>
    <span class="hljs-built_in">echo</span> <span class="hljs-string">"Starting <span class="hljs-variable">$TYPE</span>"</span>
    <span class="hljs-comment"># Clear Optimizer+ cache</span>
    curl http://autoloadbench/optimizer_clear.php
    <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> {1..10};<span class="hljs-keyword">do</span>
        curl http://autoloadbench/<span class="hljs-variable">$TYPE</span>
    <span class="hljs-keyword">done</span>
<span class="hljs-keyword">done</span>
</code></pre>
<p>I reran the tests a few times to ensure I wasn't seeing anomalies. While the
actual numbers I received differed between iterations, statistically, they only
varied within a few percentage points between runs.</p>
<h2>The Results</h2>
<h3>No Opcode Cache</h3>
<table>
<thead>
<tr>
<th align="left">Strategy</th>
<th align="right">Average Time (s)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Baseline</td>
<td align="right">0.0067</td>
</tr>
<tr>
<td align="left">ZF1 autoloader (inc path)</td>
<td align="right">1.2153</td>
</tr>
<tr>
<td align="left">PSR-0 (no include_path)</td>
<td align="right">1.0758</td>
</tr>
<tr>
<td align="left">Class Map (include_path)</td>
<td align="right">0.9796</td>
</tr>
<tr>
<td align="left">Class Map (<code>__DIR__</code>)</td>
<td align="right">0.9800</td>
</tr>
<tr>
<td align="left">SPL closure</td>
<td align="right">0.9520</td>
</tr>
</tbody>
</table>
<h3>With Opcode Cache</h3>
<table>
<thead>
<tr>
<th align="left">Strategy</th>
<th align="center">Average over all (s)</th>
<th align="center">Unaccel</th>
<th align="center">Shortest</th>
<th align="center">Ave. Accelerated</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Baseline</td>
<td align="center">0.0061</td>
<td align="center">0.0053</td>
<td align="center">0.0052</td>
<td align="center">0.0062</td>
</tr>
<tr>
<td align="left">ZF1 autoloader (inc_path)</td>
<td align="center">0.4855</td>
<td align="center">1.4444</td>
<td align="center">0.3653</td>
<td align="center">0.3789</td>
</tr>
<tr>
<td align="left">PSR-0 (no include_path)</td>
<td align="center">0.4021</td>
<td align="center">1.5477</td>
<td align="center">0.2437</td>
<td align="center">0.2748</td>
</tr>
<tr>
<td align="left">Class Map (include_path)</td>
<td align="center">0.3022</td>
<td align="center">1.2755</td>
<td align="center">0.1724</td>
<td align="center">0.1941</td>
</tr>
<tr>
<td align="left">Class Map (<code>__DIR__</code>)</td>
<td align="center">0.2568</td>
<td align="center">1.2253</td>
<td align="center">0.1362</td>
<td align="center">0.1492</td>
</tr>
<tr>
<td align="left">SPL closure</td>
<td align="center">0.2630</td>
<td align="center">1.2971</td>
<td align="center">0.1341</td>
<td align="center">0.1481</td>
</tr>
</tbody>
</table>
<h3>Analysis</h3>
<p>The three class map variants are the clear winners here, showing around a 25%
improvement on the ZF1 autoloader when no acceleration is present, and 60–85%
improvements when an opcode cache is in place. The three classmap approaches are
roughly equivalent when no opcode caching is in place, but the variants that do
not use the <code>include_path</code> are statistically faster when the opcode cache is
present.</p>
<p>Perhaps the most interesting finding for myself was seeing how much the
<code>include_path</code> affects performance, particularly when using an opcode cache. In
each case, I had the directory with my test classes listed as the first item in
the <code>include_path</code> — which is the optimal location (previous benchmarking and
profiling I've done shows that performance degrades quickly the deeper the
matching entry is within the <code>include_path</code>). Even in the non-accelerated tests,
the PSR-0 implementation, which does not use the <code>include_path</code>, is &gt;10%
faster, a difference that jumps to almost 40% with acceleration. The same
differences are true also with the class map implementations.</p>
<p>While these changes are very much micro-optimizations (remember, the numbers
above indicate <code>16^3</code> classes loaded — a single class loads in matters of
1/10,000th of a second), if you are loading hundreds or thousands of unique
classes over your application lifecycle, the evidence clearly shows some
significant performance benefits from the usage of class maps and
fully-qualified paths.</p>
<h2>Conclusions</h2>
<p>Each approach has its merits. During development, you don't want to necessarily
run a script to generate the class map or manually update the class map every
time you add a new class. That said, if you expect a lot of traffic to your
site, it's trivially easy to run a script during deployment to build the class
map for you, and thus let you eke out a little extra performance from your
application.</p>
<p>One clear realization from this experiment is that the <code>include_path</code> is a poor
way to resolve files in current incarnations of PHP. While the degradation is
not huge when your initial path matches, it still introduces a performance hit.
Additionally, it makes setup of the applications harder, as you then must
document the proper usage of the <code>include_path</code>; using <code>__DIR__</code> with either a
PSR-0-style or class map autoloader is more easily portable and requires less
education of end-users.</p>
<p>One interesting use case for a classmap based autoloader is to assist in
optimizing existing ZF1 applications. The script could be run over your
&quot;application&quot; directory to build a classmap of your application resource
classes. This would allow you to bypass the various resource autoloaders and
custom logic of the dispatcher for finding controller classes. It could also
potentially serve as one part of a migration suite between ZF1 and ZF2.</p>
<p>I will be recommending that Zend Framework 2.0 use both PSR-0 and class map
strategies, without reliance on the <code>include_path</code>, and provide tools and
scripts to aid deployment.</p>


<div class="h-entry">
    <img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&u=79dd2ea1d4d8855944715d09ee4c86215027fa80&s=140" alt="matthew">
    <a class="u-url u-uid p-name" href="https://mwop.net/blog/245-Autoloading-Benchmarks.html">Autoloading Benchmarks</a> was originally
    published <time class="dt-published" datetime="2010-08-17T09:30:00-05:00">17 August 2010</time>
    on <a href="https://mwop.net">https://mwop.net</a> by
    <a rel="author" class="p-author" href="https://mwop.net">Matthew Weier O&#039;Phinney</a>.
</div>
]]></content:encoded>
      <slash:comments>0</slash:comments>
    </item>
    <item>
      <title>2007 Retrospective</title>
      <pubDate>Thu, 03 Jan 2008 06:22:35 -0600</pubDate>
      <link>https://mwop.net/blog/154-2007-Retrospective.html</link>
      <guid>https://mwop.net/blog/154-2007-Retrospective.html</guid>
      <author>contact@mwop.net (Matthew Weier O'Phinney)</author>
      <dc:creator>Matthew Weier O'Phinney</dc:creator>
      <content:encoded><![CDATA[<p>2007 was a busy year, both personally and professionally. I won't go into the
personal too much, because, well, it's personal, and some of the details
are simply inappropriate for blogging material.</p>
<p>Here's the short version:</p>
<ul>
<li>One trip to Belgium and The Netherlands.</li>
<li>Two trips to Israel.</li>
<li>Two trips to Atlanta, GA (not counting the return trip from Europe, when I was stranded for a day due to storms in the Northeast).</li>
<li>Three different user groups attended, with three presentations.</li>
<li>One major Zend Framework release</li>
<li>One PEAR release.</li>
<li>One podcast.</li>
<li>One webinar.</li>
<li>One book published.</li>
<li>One conference attended.</li>
</ul>
<p>What follows is my month-by-month breakdown:</p>


<h3>January</h3>
<p>I finished up the last of my three chapters for
<a href="http://sitepoint.com/books/phpant2/">The PHP Anthology, 2nd Edition</a>,
and promptly used my advance to buy the family a Wii.</p>
<p>I was also introduced to <a href="http://jansch.nl/">Ivo Jansch</a> through work, and had
him wow me with one of the <a href="http://ibuildings.nl">ibuildings</a> products.</p>
<h3>February</h3>
<p>Mid-month, my boss at <a href="http://www.zend.com/">Zend</a>, Boaz, got the go-ahead to
use the ibuildings WDE platform to build our new website CMS; part of the plan
would include training at the ibuildings home office in Vlissingen, NL… which
meant I had to get my passport pronto.</p>
<p>Towards the end of the month, I was invited to <a href="http://bostonphp.org">BostonPHP</a>
to present building a simple <a href="http://framework.zend.com/">Zend Framework</a> CRUD
application, along with <a href="http://hagunbu.ch/">Chuck Hagenbuch</a> of the
<a href="http://horde.org/">HORDE project</a>. While there,
<a href="http://cake.insertdesignhere.com/">Nate Abele</a> heckled me, and then joined
Chuck and myself for an impromptu framework panel; a good time was had by all.</p>
<h3>March</h3>
<p>I flew to Brussels, Belgium, where I met my supervisor, Boaz, so we could go to
Vlissingen. We spent the day in Brussels, walking around and visiting such sites
as the Cathedral of St. Michael, La Grand Place, and the Mannekin Pis.</p>
<p>Our visit to ibuildings was very productive, and I was very impressed by the
team there; everybody was very knowledgeable and skilled. I presented a Zend
Framework overview, as well as an abbreviated version of the Best Practices talk
I'd given with Mike Naberezny at the 2006 ZendCon; the latter ignited a ton of
questions and enthusiasm.</p>
<p>On returning home, I had a ton of work to do on the zend.com CMS, and this
continued in spurts through November. The job was made much easier by the
ibuildings WDE product.</p>
<p>I closed out a ton of MVC issues in the Zend Framework, and we released the
first beta version late in the month.</p>
<h3>April</h3>
<p>At the beginning of the month, our landlord threw us for a loop and announced he
was going to sell our apartment… meaning that we either had to step up our
plans to purchase a home, or start looking for a new rental. Ultimately, we
ended up looking for a rental, due to time constraints. The next two months
would be highlighted with the look for a new place as well as countless showings
of our apartment to potential buyers.</p>
<p>Mid-month, we packed up the family and flew down to Atlanta, GA, to visit my
wife's family. While there, we were able to go to the Atlanta Zoo and see Mei
Lan, their baby panda — way cute!</p>
<h3>May</h3>
<p>Mid-month, we found a new place in Richmond, VT — a small village about 10
minutes from Burlington, near where we originally lived when we first moved to
Vermont.</p>
<p>During the first RC for Zend Framework, released at the end of the month, I
introduced the ViewRenderer, a feature for auto-rendering views based on the
current controller and action name — a feature common to many frameworks.
However, it ostensibly broke a ton of existing applications by being enabled by
default — not one of my more popular decisions. Since the 1.0.0 release, I've
heard little grumbling about it, and it's now often cited as an ease-of-use
feature — go figure.</p>
<h3>June</h3>
<p>The first week of June, I flew to Tel Aviv, Israel, to start training people on
the new CMS, as well as to work with our entire ebiz team to finalize the work
plan for completing the CMS. It was, needless to say, my first time to Israel or
the Middle East, and I was constantly confronted with culture shock. Europe was
an easy transition to make, but Israel was completely foreign to me —
everything from the way people drove, to the architecture, to the food was
different. Unfortunately, I arrived a day late due to a flight cancellation, and
missed the tour of Jerusalem my supervisor had planned for all of us. However,
he took me to the city of Jaffa, an Arabic city where the Israeli's originally
tried to settle before building Tel Aviv to the north. The architecture was
amazing, as were the winding, narrow streets of the old city.</p>
<p>I was also told during this trip that Andi had requested transferring me
full-time to the Zend Framework team. I would spend the next week or two
weighing my options, and ultimately decided to do so.</p>
<p>A week after I returned, we moved into our new rental in Richmond. The kids love
the new place, which has a bedroom for each of them, a yard, and porches on each
entrance.</p>
<p>Somehow, I also found time to record my first (and so far only)
<a href="http://devzone.zend.com/article/2140-PHP-Abstract-Podcast-Episode-2---Backup-or-Die">PHP Abstract podcast</a>.</p>
<h3>July</h3>
<p>We released <a href="http://framework.zend.com/">Zend Framework</a> 1.0.0 at the beginning
of the month, marking our first stable release. While many still view it as
incomplete, the overwhelming feedback has been positive, and we've had over 2
million downloads to date.</p>
<p>I accepted the transfer to the Zend Framework team, but the condition was made
that I would stay part-time on the ebiz team until the new site was launched.
This meant that the next 5 months were spent splitting my time between the two
projects, often working late and on weekends to get work done.</p>
<p>Towards the end of the month, we took a long weekend camping in Vermont's
Northeast Kingdom. The weather was unseasonably wet, but we persevered and had a
great time. 5 days of offline time was definitely needed!</p>
<p>I also finally released the first stable version of
<a href="http://pear.php.net/packages/File_Fortune">File_Fortune</a> on
<a href="http://pear.php.net/">PEAR</a>, over a year since I'd first proposed it. The
package interfaces with <code>mod_fortune</code> files, allowing both the ability to read
and write such files, with full binary compatability.</p>
<h3>August</h3>
<p>Not much to report in August, except work, work, and more work.</p>
<h3>September</h3>
<p>My ebiz supervisor, Boaz, flew me to Tel Aviv for a second time, this time to
perform a &quot;brain dump&quot; for the rest of the team before I transitioned fully out
of the team, and also to help setup our new data center and release procedures.
This time, Boaz took me to Jerusalem himself during my last full day in the
country. If you've never been to the city, you should definitely put it on your
list of things to do before you die. With my degree in religion, the place was
full of meaning for me, but it would be putting it lightly to say that religion
is palpable in the air there. We visited the Wailing Wall, the Via Dolorosa, the
Church of the Holy Sepulchre, and listened to the muezzins sing the call to
prayer for the muslims. The tour was simply amazing.</p>
<p>A few days after I returned, I flew down to New York City for a special meeting
of <a href="http://nyphp.org/">NYPHP</a>, where <a href="http://blogs.zend.com/author/mark/">Mark de Visser</a>
presented on various Zend products and initiatives, and I gave a Zend Framework overview.</p>
<p>A week after the NYPHP presentation, I did a <a href="http://www.zend.com/webinars">zend.com webinar</a>
on the Zend Framework MVC layer.</p>
<h3>October</h3>
<p>October was the month of <a href="http://www.zendcon.con/">ZendCon</a>. I presented a
full-day tutorial on best practices and unit testing with
<a href="http://sebastian-bergmann.de/">Sebastian Bergmann</a> and
<a href="http://naberezny.com/">Mike Naberezny</a>; despite the length and subject matter,
we were SRO for most of the day.</p>
<p>I also did a main-stage presentation on Zend Framework's MVC components,
directly following <a href="http://terrychay.com/blog/">Terry Chay</a> — an intimidating
situation at best. From the feedback I've seen, the presentation was
well-received, and I had somewhere between 120 and 150 attendees — phenomenal!
(Even more amazing was how many people were familiar with MVC in general!)</p>
<p>One great thing about the conference was the fact that I got to network with a
number of framework developers, both Zend Framework and otherwise, including
Nate Abele of CakePHP as well as <a href="http://paul-m-jones.com">Paul M. Jones</a> of
<a href="http://solarphp.com">the Solar framework</a>. Many good conversations were had.</p>
<p>Late in the month, <a href="http://sitepoint.com/books/phpant2/">The PHP Anthology, 2nd Edition</a>,
my first published book as an author, was finally released!</p>
<h3>November</h3>
<p>I spent much of the month working on
<a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Layout">Zend_Layout</a>, a
much requested component that simplifies and automates Two Step Views in Zend
Framework. I also started work implementing <a href="http://framework.zend.com/wiki/pages/viewpage.action?pageId=33071">Zend_View Enhanced</a>,
a set of view helpers for making complex views with <code>Zend_View</code> possible.</p>
<p>I also started playing with <a href="http://twitter.com/">Twitter</a> a bit, and came up
with a <a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Service_Twitter">Zend_Service_Twitter</a>
proposal for interacting with the Twitter API via PHP.</p>
<p>And finally, the Sunday before Thanksgiving, we finally launched the new
<a href="http://www.zend.com/">Zend.com</a> site, which was well-received in the
blogosphere.</p>
<h3>December</h3>
<p>A goal I've had for some time has been to form a PHP user group in the
Burlington area. A friend of mine pointed out to me sometime this fall that
there's actually already <a href="http://groups.google.com/group/Burlington-VT-PHP">a Google Group</a>
formed; he and the original founder started planning a meeting for early
December. I spoke at this inaugural meeting, presenting Zend Framework's MVC
layer yet again; a good time was had by all, and a lot of enthusiasm for future
meetings was generated.</p>
<p>I finished up <code>Zend_Layout</code> and <code>Zend_View</code> Enhanced with the help of Ralph
Schindler, and got a new proposal up for
<a href="http://framework.zend.com/wiki/display/ZFPROP/Zend_Form">Zend_Form</a>, just in
time for my holidays to begin — 11 days with family and with little to no
internet connectivity during a trip to Atlanta, GA for one of only a handful of
Christmases I've spent without snow.</p>
<h2>Summary</h2>
<p>This year was <em>incredibly</em> busy — three cross-seas trips, one cross-continent
trip, a move, and several trips along the Eastern Seaboard; three user group
presentations, and eight presentations over the course of the year; one
conference; one move; one PEAR release; one podcast; one webinar; one book; and
countless hours of programming.</p>
<p>My goals for the coming year? I'm too tired to even think about it ;-).</p>


<div class="h-entry">
    <img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&u=79dd2ea1d4d8855944715d09ee4c86215027fa80&s=140" alt="matthew">
    <a class="u-url u-uid p-name" href="https://mwop.net/blog/154-2007-Retrospective.html">2007 Retrospective</a> was originally
    published <time class="dt-published" datetime="2008-01-01T16:49:26-06:00">1 January 2008</time>
    on <a href="https://mwop.net">https://mwop.net</a> by
    <a rel="author" class="p-author" href="https://mwop.net">Matthew Weier O&#039;Phinney</a>.
</div>
]]></content:encoded>
      <slash:comments>0</slash:comments>
    </item>
    <item>
      <title>File_Fortune refactored</title>
      <pubDate>Tue, 10 Jul 2007 08:34:52 -0500</pubDate>
      <link>https://mwop.net/blog/142-File_Fortune-refactored.html</link>
      <guid>https://mwop.net/blog/142-File_Fortune-refactored.html</guid>
      <author>contact@mwop.net (Matthew Weier O'Phinney)</author>
      <dc:creator>Matthew Weier O'Phinney</dc:creator>
      <content:encoded><![CDATA[<p>Over the past few evenings, I've refactored
<a href="http://pear.php.net/trackback/trackback.php?id=File_Fortune">File_Fortune</a> to
have it implement <code>Iterator</code>, <code>Countable</code>, and <code>ArrayAccess</code> — basically allowing it
to act like an array for most intents and purposes. As a result, I've eliminated
the need for the <code>File_Fortune_Writer</code> package, and greatly simplified the
usage.</p>
<p>(Note: sure, <code>File_Fortune</code> may not be that big of a deal, but over 1000
downloads in the past two years indicates <em>somebody</em> is using it. Plus, it
powers the random quotes on the family website. :-) )</p>
<p>As some examples:</p>
<pre><code class="language-php hljs php" data-lang="php"><span class="hljs-keyword">require_once</span> <span class="hljs-string">'File/Fortune.php'</span>;

<span class="hljs-comment">// Initialize and point it to a directory of fortunes</span>
$fortunes = <span class="hljs-keyword">new</span> File_Fortune(<span class="hljs-string">'/path/to/fortunedir'</span>);

<span class="hljs-comment">// Retrieve a random fortune </span>
<span class="hljs-comment">// (works with either a directory or a single fortune file)</span>
<span class="hljs-keyword">echo</span> $fortunes-&gt;getRandom();

<span class="hljs-comment">// Set to a specific fortune file:</span>
$fortunes-&gt;setFile(<span class="hljs-string">'myfortunes'</span>);

<span class="hljs-comment">// Loop through and print all fortunes</span>
<span class="hljs-keyword">foreach</span> ($fortunes <span class="hljs-keyword">as</span> $fortune) {
    <span class="hljs-keyword">echo</span> str_repeat(<span class="hljs-string">'-'</span>, <span class="hljs-number">72</span>), <span class="hljs-string">"\n"</span>, $fortune, <span class="hljs-string">"\n\n"</span>;
}

<span class="hljs-comment">// Hmmm.. let's change one:</span>
$fortunes[<span class="hljs-number">7</span>] = <span class="hljs-string">"I never really liked that fortune anyways."</span>;

<span class="hljs-comment">// No need to explicitly save, as it's done during __destruct(), </span>
<span class="hljs-comment">// but if you really want to:</span>
$fortunes-&gt;save();

<span class="hljs-comment">// Let's add a new fortune:</span>
$fortunes-&gt;add(<span class="hljs-string">'This is a shiny new fortune!'</span>);

<span class="hljs-comment">// and now we'll verify it exists:</span>
$index = count($fortunes) - <span class="hljs-number">1</span>;
<span class="hljs-keyword">echo</span> $fortunes[$index];
</code></pre>
<p>All-in-all, it's a much better interface. Lesson learned: when porting code from
other languages, it pays to take some time and determine if there might be a
better API in your own.</p>
<p>In upcoming releases, I hope to modify the backend to use PHP's Streams API
instead of direct file access, and also to allow providing a list of fortune
files explicitly. After that, I should be ready for the initial stable release.</p>
<p><strong>Update (2007-07-10): fixed parse error in examples</strong></p>




<div class="h-entry">
    <img class="u-photo photo" width="50" src="https://avatars0.githubusercontent.com/u/25943?v=3&u=79dd2ea1d4d8855944715d09ee4c86215027fa80&s=140" alt="matthew">
    <a class="u-url u-uid p-name" href="https://mwop.net/blog/142-File_Fortune-refactored.html">File_Fortune refactored</a> was originally
    published <time class="dt-published" datetime="2007-07-05T17:26:00-05:00">5 July 2007</time>
    on <a href="https://mwop.net">https://mwop.net</a> by
    <a rel="author" class="p-author" href="https://mwop.net">Matthew Weier O&#039;Phinney</a>.
</div>
]]></content:encoded>
      <slash:comments>0</slash:comments>
    </item>
  </channel>
</rss>
