<?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>Professional PHP</title>
	<atom:link href="http://www.procata.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.procata.com/blog</link>
	<description>PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.</description>
	<lastBuildDate>Tue, 20 Oct 2009 00:57:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ZendCon: Writing Maintainable PHP Code</title>
		<link>http://www.procata.com/blog/archives/2009/10/19/zendcon-writing-maintainable-php-code/</link>
		<comments>http://www.procata.com/blog/archives/2009/10/19/zendcon-writing-maintainable-php-code/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 00:57:46 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[zendcon]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=305</guid>
		<description><![CDATA[I&#8217;ve finally made it to my first Zendcon.  Its nice to see some familiar faces and also nice to put new faces to familiar names.
I gave my maintainable PHP talk this morning.  I love doing this talk.  Thanks to everyone who attended. I&#8217;ve put the slides (pdf) up on my talks page.
Much [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally made it to my first Zendcon.  Its nice to see some familiar faces and also nice to put new faces to familiar names.</p>
<p>I gave my maintainable PHP talk this morning.  I love doing this talk.  Thanks to everyone who attended. I&#8217;ve put the <a href="http://www.procata.com/talks/zendcon-oct2009-maintainable.pdf">slides</a> (pdf) up on my <a href="http://www.procata.com/talks/">talks</a> page.</p>
<p>Much of the material is based on Test Pattern <a href="http://www.procata.com/writings/">columns that I&#8217;ve written</a> for php|architect.  Here are some of the specific columns.</p>
<dt><a href="http://www.phparch.com/magazine/index/40">Organizing For Change</a></dt>
<dd>This is where I developed the outline for the talk</dd>
<dt><a href="http://www.phparch.com/magazine/index/43">Dependency Injection</a></dt>
<dd>This is a more in depth discussion of code reuse and dependency injection</dd>
<dt><a href="http://www.phparch.com/magazine/index/65">Modeling Dependencies</a></dt>
<dd>This is where I talk about coupling, layered design and abstraction</dd>
<dt><a href="http://www.phparch.com/magazine/index/69">A Closer Look at Cohesion</a></dt>
<dd>This is where I developed my explanations of cohesion and the single responsibility principle</dd>
<dt><a href="http://www.phparch.com/magazine/index/73">Searching the Code</a></dt>
<dd>Good designs are searchable</dd>
<p>One thing I like about both writing on and presenting on the same material is that I get feedback from the presentations that I can put back into the writing and vise versa.  I&#8217;m looking forward to finding some better ways to explain layering and the depend on abstractions principle.  If you saw the talk, was there anything you particularly liked or needed work?  Leave a comment here or on the <a href="http://joind.in/877">joined.in</a> page.</p>
<p>Here are some of the books I mentioned in the talk.</p>
<dt><a href="http://www.amazon.com/gp/product/1932394753?ie=UTF8&#038;tag=procata&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=1932394753">PHP in Action: Objects, Design, Agility</a></dt>
<dd>This is a really good next step if you&#8217;re interested in maintainable code, testing, and object oriented design.</dd>
<dt><a href="http://www.amazon.com/gp/product/0201485672?ie=UTF8&#038;tag=procata&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0201485672">Refactoring: Improving the Design of Existing Code</a></dt>
<dd>This is the classic treatment of Refactoring.  Probably everyone considering themselves a professional programmer should read this.  The examples are in Java, though.</dd>
<dt><a href="http://www.amazon.com/gp/product/0131177052?ie=UTF8&#038;tag=procata&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0131177052">Working Effectively with Legacy Code</a></dt>
<dd>This is a good book if you want to start testing and refactoring in a large system that doesn&#8217;t currently have tests.  Again, the examples are in Java.</dd>
<p>I sat in on the <a href="http://joind.in/talk/view/884">PHP Code Review</a> talk this afternoon.  I thought it was a great complement to my talk.  I tend to be a bit theoretical and this talk was very practical, but we covered a lot of the same principles.  Nice talk.  Nice scheduling, Zend.</p>
<p>I&#8217;m really looking forward to tomorrow.  Unfortunately, I have to go back to work on Wednesday.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2009/10/19/zendcon-writing-maintainable-php-code/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Looking Towards the Cloud</title>
		<link>http://www.procata.com/blog/archives/2009/05/02/looking-towards-the-cloud/</link>
		<comments>http://www.procata.com/blog/archives/2009/05/02/looking-towards-the-cloud/#comments</comments>
		<pubDate>Sat, 02 May 2009 19:11:45 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[ec2]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=295</guid>
		<description><![CDATA[Some people love their automobiles.  They can tell you all all about their technical specifications.  They buy upgrades and after market parts.  Its a lifestyle and a hobby.  I am not one of those people.  For me an automobile is purely a means to an end.  I am here, [...]]]></description>
			<content:encoded><![CDATA[<p>Some people love their automobiles.  They can tell you all all about their technical specifications.  They buy upgrades and after market parts.  Its a lifestyle and a hobby.  I am not one of those people.  For me an automobile is purely a means to an end.  I am here, I want to be there.  Having lived the last year without a car (my truck is in storage and will be for sale soon), I can say I don&#8217;t much care whether I get there in my car, or a taxi, or a zip car.  This is the benefit of modern urban living, I suppose.</p>
<p>So, just as I look at an automobile as a means to an end, I look at servers as a means to an end.  I guess that makes me a Software Guy.  I know there are Hardware Guys out there.  They&#8217;re doing great things and I&#8217;m thankful for them.  But, for the most part, I am interested in what computers can do for us, not how they do it.</p>
<p>I don&#8217;t think I&#8217;m alone in my attitude.  That&#8217;s why I think that computing as a commodity a strong future.  We can leave things like <a href="http://www.youtube.com/watch?v=zRwPSFpLX8I">data center efficiency</a> to someone else and focus on the things that are really important to us.  Oh, if you&#8217;re at facebook scale, you&#8217;re probably going to have to do <a href="http://www.facebook.com/note.php?note_id=76191543919&#038;ref=mf">serious cross stack optimization</a>.   And if you are at the hobby end, current cloud offerings may be pricy.</p>
<p>But, consider this.  What can you buy with $100,000 per year?  One programmer or 120 ec2 instances.  (more with reserved instance pricing.)</p>
<p><img src='http://www.procata.com/blog/wp-content/images/cloud.043.jpg' alt='Cloud Computing Versus Programming Talent' class='aligncenter' /></p>
<p>At a certain scale, cloud computing makes alot of sense.  $100,000 is just a number. Oh, I know, you have this guy in Belarus and he works for less.  But, the fundamental equation is the same.  Programming is expensive and computing power is a commodity.  Did I mention I&#8217;m a software guy?</p>
<p>Are you interested in how to use PHP in the cloud?  Clay Loveless recognized the advantages of cloud computing early, jumping on ec2 as one of the early adaptors.  He&#8217;s recently written a great <a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2433">Introduction to AWS for PHP Programmers</a>.  I&#8217;d encourage you to check it out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2009/05/02/looking-towards-the-cloud/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Holiday Tech Support</title>
		<link>http://www.procata.com/blog/archives/2009/04/11/holiday-tech-support/</link>
		<comments>http://www.procata.com/blog/archives/2009/04/11/holiday-tech-support/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 17:18:48 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[tech-support]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=294</guid>
		<description><![CDATA[I don&#8217;t see my family as often since I&#8217;ve moved to San Francisco.  This weekend I&#8217;m home for the Easter holiday.  Its nice to see everyone.  Additionally, I have a backlog of tech support for my parents and grandparents.  I&#8217;ve installed software purchased months ago, done updates that they weren&#8217;t even [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t see my family as often since I&#8217;ve moved to San Francisco.  This weekend I&#8217;m home for the Easter holiday.  Its nice to see everyone.  Additionally, I have a backlog of tech support for my parents and grandparents.  I&#8217;ve installed software purchased months ago, done updates that they weren&#8217;t even are of, installed a router and fixed rats nests of cables.  I&#8217;ve restored TV setups to working order and am about to fix a vacuum cleaner.  Are you the tech support guy for your family?  What are you fixing this weekend?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2009/04/11/holiday-tech-support/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Closures are coming to PHP</title>
		<link>http://www.procata.com/blog/archives/2009/03/22/closures-are-coming-to-php/</link>
		<comments>http://www.procata.com/blog/archives/2009/03/22/closures-are-coming-to-php/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 22:09:16 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[closures]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=293</guid>
		<description><![CDATA[Dagfinn has a post looking at using the new closure feature of PHP 5.3.  He compares using foreach for iteration versus array_map. &#8220;Interesting,&#8221; he concludes, &#8220;but not necessarily better than conventional alternatives.&#8221;
I agree for that case.  Consider instead, a more complicated operation that requires a setup and a tear down after.
&#160;
setup&#40;&#41;;
operation&#40;&#41;;
teardown&#40;&#41;;
&#160;
Now what happens [...]]]></description>
			<content:encoded><![CDATA[<p>Dagfinn has a <a href="http://blog.agilephp.com/2009/03/19/real-programming-with-php-53-part-1-array-processing/">post</a> looking at using the new closure feature of PHP 5.3.  He compares using foreach for iteration versus array_map. &#8220;Interesting,&#8221; he concludes, &#8220;but not necessarily better than conventional alternatives.&#8221;</p>
<p>I agree for that case.  Consider instead, a more complicated operation that requires a setup and a tear down after.<br />
<pre class="php">&nbsp;
setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
operation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>Now what happens if we need to be able to customize operation?  That&#8217;s common enough, one way of doing this is to create a template method.</p>
<p><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyExample <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> operation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> doit<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setup</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">operation</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">teardown</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<p>Now, we can subclass MyExample and override operation() with custom logic.  This is well and good, but what the customization we need is fairly small.  Creating a new class carries a certain weight.  Especially if you are religious about one class per file.  </p>
<p><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyExampleExtension <span style="color: #000000; font-weight: bold;">extends</span> MyExample <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> operation<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #808080; font-style: italic;">// custom logic</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<p>Plus, you now have to deal with some creational patterns to make sure your custom class is used in the right context.</p>
<p><pre class="php">&nbsp;
<span style="color: #0000ff;">$myObject</span> = <span style="color: #0000ff;">$registery</span>-&gt;<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'MyExample'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$myObject</span>-&gt;<span style="color: #006600;">doit</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>So, instead of encapsulating the pattern, its also very common to just copy and paste:</p>
<p><pre class="php">&nbsp;
setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
custom_operation1<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">//...</span>
setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
custom_operation2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>But that&#8217;s not good on the duplicate code front.  So here is an alternate implementation, but using a <del datetime="2009-03-24T17:34:07+00:00">closure</del> anonymous function as a callback.</p>
<p><pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyExample2 <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> teardown<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">function</span> doit<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$operation</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">setup</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$operation</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$this</span>-&gt;<span style="color: #006600;">teardown</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></p>
<p>The advantage of MyExample2 is that extending is that the setup and teardown pattern is encapsulated in one spot.  You konw that if setup is called, teardown will also be called.  But, extending the operation is very light weight.</p>
<p><pre class="php">&nbsp;
<span style="color: #0000ff;">$myObject</span> = <span style="color: #000000; font-weight: bold;">new</span> MyExample2<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$myObject</span>-&gt;<span style="color: #006600;">doIt</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">/* custom logic 1 */</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// ...</span>
<span style="color: #0000ff;">$myObject</span>-&gt;<span style="color: #006600;">doIt</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">/* custom logic 2 */</span> <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></p>
<p>There is  another significant benefit to this and that is locality of reference.  Here, the custom1 logic and the custom2 logic appears in context, not far away in some custom class or function declaration.  So you get encapsulation and reuse for the common code parts, but without the sprawl and overhead of declaring structures that will only be used once in a context far away their declaration.</p>
<p>Closures and anonymous functions decrease the activation energy to write good code.</p>
<p>That&#8217;s not to say that closures and anonymous functions can&#8217;t be abused.  If you keep seeing the same logic over and over in an anonymous block, you should probably give it a name in the form of a class, method or function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2009/03/22/closures-are-coming-to-php/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>php &#124; tek Wrapup</title>
		<link>http://www.procata.com/blog/archives/2008/05/26/php-tek-wrapup/</link>
		<comments>http://www.procata.com/blog/archives/2008/05/26/php-tek-wrapup/#comments</comments>
		<pubDate>Tue, 27 May 2008 05:57:30 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[phptek]]></category>
		<category><![CDATA[talks]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=290</guid>
		<description><![CDATA[I really enjoyed myself at this year&#8217;s php &#124; tek.  The conference seemed even better than last year.  Here are the slides from my talks&#8230;

Exceptional PHP
Coding for Success: Writing Software You’ll Be Able To Understand Next Month

Here are some of the books I mentioned&#8230;

Refactoring: Improving the Design of Existing Code
php&#124;architect&#8217;s Guide to PHP [...]]]></description>
			<content:encoded><![CDATA[<p>I really enjoyed myself at this year&#8217;s php | tek.  The conference seemed even better than last year.  Here are the slides from my talks&#8230;</p>
<ul>
<li><a href="http://www.procata.com/talks/phptek-may2008-exceptional.pdf">Exceptional PHP</a></li>
<li><a href="http://www.procata.com/talks/phptek-may2008-maintainable.pdf">Coding for Success: Writing Software You’ll Be Able To Understand Next Month</a></li>
</ul>
<p>Here are some of the books I mentioned&#8230;</p>
<ul>
<li><a href="http://www.amazon.com/Refactoring-Improving-Existing-Addison-Wesley-Technology/dp/0201485672/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867585&#038;sr=1-1">Refactoring: Improving the Design of Existing Code</a></li>
<li><a href="http://www.phparch.com/c/books/id/0973589825">php|architect&#8217;s Guide to PHP Design Patterns</a></li>
<li><a href="http://www.amazon.com/PHP-Action-Objects-Design-Agility/dp/1932394753/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867300&#038;sr=1-1">PHP in Action: Objects, Design, Agility</a></li>
<li><a href="http://www.amazon.com/Design-Patterns-Object-Oriented-Addison-Wesley-Professional/dp/0201633612/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867382&#038;sr=1-1">Design Patterns: Elements of Reusable Object-Oriented Software</a></li>
<li><a href="http://www.amazon.com/Implementation-Patterns-Addison-Wesley-Signature-Kent/dp/0321413091/ref=pd_bbs_sr_1?ie=UTF8&#038;s=books&#038;qid=1211867430&#038;sr=1-1">Implementation Patterns</a></li>
<li><a href="http://www.amazon.com/Fundamentals-Object-Oriented-Design-Addison-Wesley-Technology/dp/020169946X/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1211867490&#038;sr=1-1">Fundamentals of Object-Oriented Design in UML</a></li>
</ul>
<p>I&#8217;m already looking forward to next year.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2008/05/26/php-tek-wrapup/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>php &#124; tek 2008</title>
		<link>http://www.procata.com/blog/archives/2008/05/20/php-tek-2008/</link>
		<comments>http://www.procata.com/blog/archives/2008/05/20/php-tek-2008/#comments</comments>
		<pubDate>Tue, 20 May 2008 16:17:31 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2008/05/20/php-tek-2008/</guid>
		<description><![CDATA[Well, I&#8217;ve made it to PHP&#124;tek in Chicago.  I flew in last night, had a beer with Jason and then used the WiFi in the lobby to spin up an extra large EC2 instance (via RightScale) to do some benchmarks for one of my talks.  I&#8217;m using the the XL instance because it [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.procata.com/blog/wp-content/uploads/2008/05/elephant.jpg' alt='PHP Elephant' align='right' hspace='20' />Well, I&#8217;ve made it to PHP|tek in Chicago.  I flew in last night, had a beer with <a href="http://blog.casey-sweat.us/">Jason</a> and then used the WiFi in the lobby to spin up an extra large EC2 instance (via <a href="http://www.rightscale.com/m/">RightScale</a>) to do some benchmarks for one of my talks.  I&#8217;m using the the XL instance because it it is <a href="http://oren.blogs.com/praxis/2008/04/the-amazon-ec2.html">not shared</a> with other users.</p>
<p>I&#8217;m still putting the final touches on my slides.</p>
<ul>
<li><a href="http://tek.phparch.com/c/schedule/talk/d1s6/1">Exceptional PHP</a></li>
<li><a href="http://tek.phparch.com/c/schedule/talk/d2s5/0">Coding for Success: Writing Software You&#8217;ll Be Able To Understand Next Month</a></li>
</ul>
<p>I&#8217;m blogging this from <a href="http://www.cdatazone.org/">Rob Richards&#8217;</a> Working With Web Services presentation.  Oh yeah, I work with Rob.  Oh yeah, since, I haven&#8217;t posted anything in six months &#8230;  In January, I moved to San Francisco and started work at <a href="http://www.mashery.com/">Mashery</a>.  I realized from talking with Jason last night that I really haven&#8217;t mentioned that here.  They&#8217;ve been keeping me pretty busy, hence the lack of blogging.</p>
<p>php|tek is <a href="https://twitter.com/phptek">on twitter</a>.  So, I&#8217;ve finally signed up <a href="http://twitter.com/Selkirk">there</a>.  I don&#8217;t get it.  <img src='http://www.procata.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>One last thing, Mashery is <a href="http://www.mashery.com/jobs">Hiring</a> good PHP and Javascript programmers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2008/05/20/php-tek-2008/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Sarah Snow Stever</title>
		<link>http://www.procata.com/blog/archives/2007/11/23/sarah-snow-stever/</link>
		<comments>http://www.procata.com/blog/archives/2007/11/23/sarah-snow-stever/#comments</comments>
		<pubDate>Sat, 24 Nov 2007 06:36:04 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Misc]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/11/23/sarah-snow-stever/</guid>
		<description><![CDATA[
I am very sad.  Two weeks ago, my cousin Sarah had a stroke and died.  She was 35, two years younger than me.
As kids, Sarah and I, (along with her sister Rachel) would spend weeks in the summer staying at my grandparents house, playing and doing the things that ten year olds do [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.procata.com/blog/wp-content/uploads/2007/11/sarah-sm.jpg' title='Sarah'><img src='http://www.procata.com/blog/wp-content/uploads/2007/11/sarah-sm.jpg' alt='Sarah' /></a></p>
<p>I am very sad.  Two weeks ago, my cousin Sarah had a stroke and died.  She was 35, two years younger than me.</p>
<p>As kids, Sarah and I, (along with her sister Rachel) would spend weeks in the summer staying at my grandparents house, playing and doing the things that ten year olds do on a farm.  We sat around the campfire at family reunions.  We played cards and games, talked and argued.  I always looked forward to seeing all my cousins at holidays and family gatherings, but Sarah and Rachel were special then because they were closer to my age.</p>
<p>As adults, Sarah and I also did stuff together on occasion.  We still sat around the campfire at the family reunions and visited during the holidays.  But, we also went to bars and restaurants, Sarah always knew the best bars.  We went to Cedar Point and shared an automobile accident.  She would cut my hair and I would fix her computer. But mostly, we just talked.  Sarah was just plain easy to talk to and always interesting.</p>
<p>In recent years Sarah moved to Atlanta to build a life for herself there.  She opened a salon there and infused it with her character and personality.  It was a place where she was at home and happy.  I&#8217;m sure her clients felt happy and at home there as well. (<a href="http://ashleywebb.blogspot.com/2007/11/sarah-snow-stever.html">A client  remarks on Sarah&#8217;s passing</a>)</p>
<p>But, the most important thing about her move to Atlanta was meeting her husband, Kevin there.  I&#8217;ve only met Kevin a few times, but the one thing that I know about him is that he made Sarah happy.</p>
<p>I haven&#8217;t seen Sarah as much in the last few years.  Atlanta is far from Michigan and she disliked flying.  She came to fewer and fewer holiday functions.  Despite her many invitations to visit Atlanta, I didn&#8217;t go.</p>
<p>That is until September, when I went to the php|works conference in Atlanta.  One of the reasons I wanted to go to the conference was to be able to see Sarah.  After the conference, I stayed with her for a couple days.</p>
<p>Sarah showed me her Salon and I could see how much she loved it.  She introduced me to the dogs that she saved.  We went out to eat and visited the local Atlanta attractions.  But mostly, we talked.  We talked about family, dating, kids and careers.  We talked about her writing, the gym she liked, the church she had joined and the things she wanted to do.</p>
<p>Sarah tried very hard to convince me to move to Atlanta.  I think she felt that all I needed to do was to move there and I would meet the love of my life and l could live there happily to the end of my days.  After all, she did.</p>
<p>There is so much that I still want to do with Sarah.  I feel like I&#8217;ve always taken it for granted that that she would be around for us to &#8220;do that later.&#8221;  I guess not.  I&#8217;ll miss Sarah.</p>
<p><a href="http://obits.mlive.com/AnnArbor/DeathNotices.asp?Page=Lifestory&#038;PersonId=97964436">Sarah&#8217;s obituary</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/11/23/sarah-snow-stever/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		</item>
		<item>
		<title>Benchmarking PHP&#8217;s Magic Methods</title>
		<link>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/</link>
		<comments>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 00:01:02 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[performance-optimization]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/</guid>
		<description><![CDATA[Larry Garfield has an interesting set of benchmarks covering many of PHP&#8217;s magic methods.  His results correspond pretty well to my own benchmarks in the area.  The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them.  Its hard to [...]]]></description>
			<content:encoded><![CDATA[<p>Larry Garfield has an interesting <a href="http://www.garfieldtech.com/blog/magic-benchmarks">set of benchmarks</a> covering many of PHP&#8217;s <a href="http://php.net/oop5.magic">magic methods</a>.  His results correspond pretty well to my own benchmarks in the area.  The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them.  Its hard to do anything useful inside a magic method, such as __get or __call that isn&#8217;t <b>10 to 20 times slower</b> than the &#8220;non-magic&#8221; solution.</p>
<p>There are probably more than a few naive programmers who would read results like this and start to avoid these constructs in their own code for performance reasons.  These are the same kinds of people obsessing over a few single or double quotes, who eschew &#8220;slow&#8221; objects in favor of switch statements that are many times slower than the polymorphic method calls they are trying to avoid.</p>
<p>But, that&#8217;s not the end of the story.  Larry ran his benchmarks using 2,000,000 iterations.  The <b>N</b> really matters here.  Sure, iterators are slower than arrays, but you aren&#8217;t going to be iterating over two million things.  I tend to fetch my database records in lots of 25 or 50.  You aren&#8217;t going to be making two million invocations of __call.  But how many will you make?  Under what value of N does the performance of these techniques cease to matter?  Is it ten, one hundred, one thousand, or ten thousand?  You may be surprised at how few calls your program actually does and how little impact it has on performance.</p>
<p>As <a href="http://netevil.org/">Wez</a> and <a href="http://www.travisswicegood.com/">Travis</a> point out in their comments, profiling is the way to find out the potential impact and to discover your true N.</p>
<p>Paul M. Jones has a <a href="http://paul-m-jones.com/blog/?p=182">good example</a> of what I&#8217;m talking about.  There, call_user_func_array appears to be a bottleneck, but it turns out that its the function being called, htmlspecialchars, not the calling process that consumes the balance of the time.  In that case, the function was &#8220;only&#8221; called 300 times.  I find that order of magnitude to be fairly typical.  Something to be aware of, perhaps, but not something to obsess over.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>The Endpoints of the Scale of Stupidity on Video</title>
		<link>http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/</link>
		<comments>http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 20:55:22 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/</guid>
		<description><![CDATA[A quote from Cal Henderson (via simonwillison) presents a &#8220;Web Application Scale of Stupidity:&#8221;

&#124; OGF (One Giant Function) ---- Sanity ---- OOP (Object Oriented Programming) &#124;

The scale that Cal is talking about is actually better known as modularity:

&#124; Few large modules ----  Sanity? ---- Many Small Modules &#124;

If you haven&#8217;t listened to Alan Kay [...]]]></description>
			<content:encoded><![CDATA[<p>A quote from Cal Henderson (via <a href="http://simonwillison.net/2007/Nov/2/cal/">simonwillison</a>) presents a &#8220;Web Application Scale of Stupidity:&#8221;<br />
<code><br />
| OGF (One Giant Function) ---- Sanity ---- OOP (Object Oriented Programming) |<br />
</code></p>
<p>The scale that Cal is talking about is actually better known as <a href="http://sunnyday.mit.edu/16.355/parnas-criteria.html">modularity</a>:</p>
<p><code><br />
| Few large modules ----  Sanity? ---- Many Small Modules |<br />
</code></p>
<p>If you haven&#8217;t listened to Alan Kay talk about the benefits of many small modules, you should do so now.  Alan Kay coined the term Object Oriented.  Love OO or hate OO, if you have an opinion on it, you should know what he was thinking.  Hint, it wasn&#8217;t C++.</p>
<p><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=-2950949730059754521&#038;hl=en" flashvars=""> </embed></p>
<p>On the other end of the scale, One Giant Function is generally known as <a href="http://www.laputan.org/pub/foote/mud.pdf">Big ball of Mud</a>(PDF)  Here is Brian Foote&#8217;s presentation on the paper (read the paper first).</p>
<p><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=8693679271218408739&#038;hl=en" flashvars=""> </embed></p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/11/02/the-endpoints-of-the-scale-of-stupidity-on-video/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Working with PHP 5 in Mac OS X 10.5 (Leopard)</title>
		<link>http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/</link>
		<comments>http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 00:48:44 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php-5]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/</guid>
		<description><![CDATA[Mac OS X is a great development platform for working with PHP.  Leopard comes with Apache, PHP and many other development tools, such as subversion already installed.  Leopard brings a much needed upgrade from Tiger&#8217;s tired PHP 4 to a very modern version of PHP 5.2.4.  This is a guide for setting [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.procata.com/blog/wp-content/uploads/2007/10/php-med-trans-light.gif' alt='PHP' align="right" />Mac OS X is a great development platform for working with PHP.  Leopard comes with Apache, PHP and many other development tools, such as subversion already installed.  Leopard brings a much needed upgrade from Tiger&#8217;s tired PHP 4 to a very modern version of PHP 5.2.4.  This is a guide for setting up a PHP development environment under 10.5 using the version of PHP that ships with leopard.</p>
<p>You may prefer to use one of the 3rd party distributions of PHP, such as <a href="http://www.mamp.info/en/index.php">MAMP</a>, <a href="http://www.apachefriends.org/en/xampp-macosx.html">XAMPP</a> or <a href="http://www.entropy.ch/software/macosx/php/">Marc Liyanage</a>.  This is a guide to using the version of PHP that comes with 10.5.</p>
<h3>Enable Developer Tools</h3>
<p>These steps may not be strictly necessary for this process, but I find it useful to do them.<br />
First, <a href="http://docs.info.apple.com/article.html?artnum=106290">enable your root password</a>.<br />
You may also want to install XCode Tools from your Leopard disk (or grab the latest from <a href="http://developer.apple.com/tools/">Apple developer tools</a>).  The tools are required is you are going to compile any extensions for PHP.</p>
<h3>Editing Configuration Files</h3>
<p>We will have to edit several configuration files that exist as part of the unixy underpinnings of OS X.  I&#8217;m going to recommend the free text editor, <a href="http://www.barebones.com/products/textwrangler/">TextWrangler</a> for this purpose.  Normally, the finder hides the configuration files from view.  However, in the finder, you can use the &#8220;Goto Folder&#8230;&#8221; option under the &#8220;Go&#8221; menu to view these files.  This option if available via command-shift-G.  Actually, this option is available in any file open dialog in OS X via command-shift-G.  In addition, Text Wrangler will allow you to browse these files with its &#8220;open hidden&#8230;&#8221; option.  But, the much easier option is selecting &#8220;Open file by name&#8230;&#8221; (command-D) and just typing the full path and filename.  To save many of these files, you will need to enter your root password.  Be Careful.</p>
<h3>Enabling PHP</h3>
<p>PHP is installed in Mac OS X by default, but not enabled.  To enable it, we must edit the apache 2 configuration file, which is located at <samp>/etc/apache2/httpd.conf</samp>.  Find the line which loads the PHP 5 module, which looks like this:<br />
<code><br />
#LoadModule php5_module        libexec/apache2/libphp5.so<br />
</code><br />
The line is currently commented out.  All we have to do is remove the comment symbol, <samp>#</samp>, so the line looks like this:<br />
<code><br />
LoadModule php5_module        libexec/apache2/libphp5.so<br />
</code><br />
Save.</p>
<h3>Starting Apache</h3>
<p>Go to the sharing panel in system preferences and enable &#8220;Web Sharing.&#8221;  This will start the apache server.<br />
<a href='http://www.procata.com/blog/wp-content/uploads/2007/10/web-sharing.png' title='Sharing Panel'><img src='http://www.procata.com/blog/wp-content/uploads/2007/10/web-sharing.png' alt='Sharing Panel' /></a><br />
Another way to do this is to type the following in the Terminal application:<br />
<code><br />
sudo apachectl start<br />
</code><br />
You will be prompted to enter your root password.  After that, your apache server should now be running.  If you need to restart the server from the terminal, you can type this:<br />
<code><br />
sudo apachectl restart<br />
</code><br />
If you find this tedious to type, there is a script that you can download to do this later in this post.</p>
<h3>Visiting our Web Site</h3>
<p>Now, lets check our work.  In the sharing panel, you can click on the URL under &#8220;Your computer&#8217;s website.&#8221;  Alternatively, in the web browser, go to the url <a href="http://localhost/">http://localhost/</a>.  localhost is a special name that means &#8220;My computer.&#8221;  If your web server is working, you should see a page titled &#8220;Test Page for Apache Installation.&#8221;  If you go to <a href="http://localhost/manual/">http://localhost/manual/</a>, you can read an Apache 2.2 manual, hosted from your own server.  But, this don&#8217;t tell you that PHP is working.<br />
For that, we&#8217;ll have to create a very simple php program.  Create a new file in TextWrangler and type the following:<br />
<pre class="php">&nbsp;
&lt; ?php <a href="http://www.php.net/phpinfo"><span style="color: #000066;">phpinfo</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre><br />
(Don&#8217;t just copy and paste this.  Note that there should be no space between the <samp>&lt;</samp> and the <samp>?php</samp>.  The WordPress software I use for this blog inserts an extra space.)<br />
Save this using the file name <samp>info.php</samp> in the <samp>/Library/WebServer/Documents/</samp> directory.  (start from the top level directory of your hard drive, not the library directory in your home directory.  Now you should be able to visit the PHP page you just created by visiting <a href="http://localhost/info.php">http://localhost/info.php</a>.  You should see the PHP logo and a big table of configuration information.</p>
<h3>Showing the World</h3>
<p>For security purposes, you should consider that anything you put in your <samp>WebServer/Documents</samp> folder will be available across the web.  If you have information that you want to keep private, think twice about putting it there, unless you know how to protect it.<br />
But, if you want people to see the pages that you are sharing, there can be a few obstacles.  You can give out the URL that is listed in the sharing control panel under &#8220;Your computer&#8217;s website.&#8221;  However, if you are behind a <a href="http://en.wikipedia.org/wiki/Network_address_translation">NAT</a> router, such as I am, this IP address based url will only work for other computers on your network and not for the internet as a whole.  You may have to configure network router or firewall in order to discover your true ip address and to route web server requests to that IP to your computer.  Doing this is beyond the scope of this tutorial.<br />
Additionally, IP address based urls don&#8217;t make good urls to share.  IP addresses can change.  If you plan to host a permanent web site, you may want to purchase a domain name and point it to your Mac.  This also, is beyond the scope of this tutorial.<br />
Perhaps the best option is to purchase both a domain name and professional hosting.  Apache based PHP Hosting is widely available and cheap.  You can get support from a good host on uploading your files to the remote server.  I&#8217;m going to presume that you will use one of the many excellent PHP hosting options and are only configuring PHP on your own machine for education, testing or development purposes.</p>
<h3>Enabling a Personal Website</h3>
<p>If you clicked on the URL under &#8220;Your Personal Website,&#8221; you might have gotten a page that says forbidden.  This is because in the default configuration in Leopard, unlike in Tiger, does not allow Apache to serve documents from home directories.  If you want to enable this feature, you have to create a new Configuration file.<br />
Create a new file with the following contents and save it to <samp>/etc/apache2/users/jeff.conf</samp>.<br />
<pre class="xml">&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;directory</span> <span style="color: #ff0000;">&quot;/Users/jeff/Sites&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/directory<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;</pre><br />
Replace &#8220;jeff&#8221; with your user name, which is also the name of your home directory.  Exact capitalization is imporant.  This tells the Apache server that it is ok to serve web content out of the <samp>~jeff</samp> directory.  You will have to restart Apache for this to take effect.<br />
You may also have to create a <samp>Sites</samp> folder in your home directory to hold the files you want to serve.  Leopard will automatically bless this folder with a special Icon.</p>
<h3>Virtual Hosting</h3>
<p>If you want to experiment with or work on more than one site at a time, the single directory in WebServer Documents and the Personal Websites configuration don&#8217;t work well.  Projects collide and files outside of your home directory can be harder to work with.  The answer to this is to setup virtual hosting.  Lets turn our Personal Website sharing solution into a virtual hosting solution that allows us to work with multiple websites as subdirectories of our Sites folder.<br />
So, lets create a sample site, called mysite.  We&#8217;ll create a folder called &#8220;mysite&#8221; as a sub folder of our Sites folder.  Capitalization is important.<br />
Now, we are going to want to access our site with an easy to use domain name, so that our url is <samp>http://mysite/</samp>.  There is an easy way to create new domain names that are only for personal use.  To do this, we can add it to our <samp>/etc/hosts</samp> file.  Add the following lines at the end of this file:<br />
<code><br />
# My local aliases<br />
127.0.0.1	mysite<br />
</code><br />
127.0.0.1 is a special IP address designation that never changes and corresponds to localhost to mean this computer.  We are telling our Mac that the name mysite is hosted on the local computer.  This rule is only in effect on the same machine.  If you go to a different machine, you cannot use the <samp>http://mysite/</samp> url.<br />
Now we need to configure apache for virtual hosting.  We are going to have to edit our <samp>/etc/apache2/users/jeff.conf</samp> file.  Change the contents of this file to the following:<br />
<pre class="xml">&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;directory</span> <span style="color: #ff0000;">&quot;/Users/jeff/Sites/*/&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/directory<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;
NameVirtualHost *:80
&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;virtualhost</span> *:<span style="color: #cc66cc;">80</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    DocumentRoot /Users/jeff/Sites/mysite
    ServerName mysite
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/virtualhost<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;</pre><br />
Remember to replace &#8220;jeff&#8221; with your user name.  Place your <samp>info.php</samp> test file into the mysite directory and rename it to <samp>index.php</samp>.  Now, restart your apache server.  When you visit <samp>http://mysite/</samp>, you should now see the familiar php logo and information page.<br />
If you want to add another site, just add a second line in your hosts file, another subdirectory of Sites and append the following to your apache configuration file:<br />
<pre class="xml">&nbsp;
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;virtualhost</span> *:<span style="color: #cc66cc;">80</span><span style="font-weight: bold; color: black;">&gt;</span></span>
    DocumentRoot /Users/jeff/Sites/myothersite
    ServerName myothersite
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/virtualhost<span style="font-weight: bold; color: black;">&gt;</span></span></span>
&nbsp;</pre></p>
<h3>Sharing with the World, Part II</h3>
<p>Sharing your virtual hosted sites with the world is more complicated if you don&#8217;t have a domain name setup.  You can, however, add your hosts files entries to other computers that you want to share with.  However, you have to change the 127.0.0.1 IP address to the IP address of your computer, taking into account any NAT.<br />
There is a special case of this.  If you are using parallels, perhaps for test viewing your pages in internet explorer, you may want your virtual hosted sites to be available.  The good news is that Windows also supports a <a href="http://en.wikipedia.org/wiki/Hosts_file">hosts</a> file. Here is how to <a href="http://www.mvps.org/winhelp2002/hostsfaq.htm">edit your windows hosts file</a>.  The big problem is knowing what IP address to use.  You can&#8217;t use 127.0.0.1 on the windows side because that is the virtual windows machine, not your Mac&#8217;s address.   You can use the IP address shown on your network system preferences panel, 192.168.1.100 for me.  But, this number is subject to change and you will have to re-edit your hosts file on the windows side.<br />
If you are using Parellels, be sure to upgrade to the new <a href="http://www.parallels.com/en/products/desktop/beta/">beta version</a> for Leopard, build 5540.  Once you&#8217;ve done that, if you visit the network panel in system preferences and select the &#8220;Parallels Host-Guest&#8221; network, you will see the IP address that parallels assigns to your host machine.  (assuming you are using Shared Networking.)  You can then use this IP address in your windows hosts file.  You may also be able to change &#8220;Using DHCP&#8221; to &#8220;Using DHCP with Manual address&#8221; and re-entering this number if you have a problem with the number changing.  Here, my number is 10.37.129.3:</p>
<p><img src='http://www.procata.com/blog/wp-content/uploads/2007/10/parallels.png' alt='Network Preferences panel' /></p>
<h3>Installing MySQL</h3>
<p>MySQL has a binary distribution for Mac OS X.  They also have reasonably good documentation on <a href="http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html">installing MySQL on Mac OS X</a> for their distribution.  Note that Leopard specific packages for MySQL have not been created yet.</p>
<h3>Starting MySQL</h3>
<p>So far, the MySQL preferences panel from the Tiger release is broken and does not correctly start and stop MySQL (<a href="http://bugs.mysql.com/bug.php?id=31889">bug report</a>.  You can do this from the terminal window with<br />
<code><br />
sudo /usr/local/mysql/support-files/mysql.server start<br />
</code><br />
To shutdown the server type:<br />
<code><br />
sudo /usr/local/mysql/support-files/mysql.server stop<br />
</code><br />
If you find this tedious to type, you can download <a href="http://www.procata.com/software/WebDevCP.dmg">WebDevCP</a>, which is a small AppleScript application that I made. Launching WebDevCP launches both Apache and MySQL.  Quitting the application shuts them both down.  usually.  Launching and quitting requires a password.  No warranty on this thing.  It was just something I was using personally and figured others might find useful.</p>
<h3>Bring the mysql.sock to PHP</h3>
<p>One problem that has come about with MySQL and Leopard is the location of the <samp>mysql.sock</samp> file.  Previously, the default location for this file was in the <samp>/tmp</samp> directory.  That location has now moved to the <samp>/var/mysql</samp> directory.  PHP will look for it there.  Unfortunately, the default location from the MySQL will still place it in the old location.  We can fix this by creating a <samp>my.cnf</samp> configuration file in the /etc directory.  Save a file with the following contents to <samp>/etc/my.cnf</samp>:<br />
<code><br />
[client]<br />
socket = /var/mysql/mysql.sock</p>
<p>[mysqld]<br />
socket = /var/mysql/mysql.sock<br />
</code><br />
In the terminal window, type the following commands to create the directory for the sock file:<br />
<code><br />
sudo mkdir /var/mysql<br />
sudo chown _mysql /var/mysql<br />
</code><br />
One drawback to this is that if you have installed the MySQL GUI tools, they will look for the <samp>mysql.sock</samp> file at the old location.  You can enter the new socket in the connection dialog under More Options, there is a box labeled &#8220;connect using socket.&#8221;  Just enter <samp>/var/mysql/mysql.sock</samp>.<br />
Another solution is to change the <samp>php.ini</samp> file to expect the socket in a different location.  I&#8217;m going with the <samp>my.cnf</samp> option because I expect the MySQL will have a Leopard version out in a few days that changes the default location.</p>
<h3>Where is PEAR?</h3>
<p>OS X has traditionally had problems with <a href="http://pear.php.net/">PEAR</a>.  Many point updates would overwrite the included version of PEAR with an older, and perhaps insecure version.  Sadly, Apple has fixed this by not including PEAR at all in their OS.  This is a big inconvenience for people wanting to use Apple&#8217;s default version of PHP, versus a third party distribution.  So, lets get PEAR installed.  Type the following in the terminal window to download the PEAR installer:<br />
<code><br />
curl http://pear.php.net/go-pear > go-pear.php<br />
</code><br />
after that, type<br />
<code><br />
sudo php -q go-pear.php<br />
</code><br />
To run it.  Hit enter to select the default locations.  PEAR will be installed, but it won&#8217;t be ready to use until we modify our <samp>php.ini</samp> file.</p>
<h3>PHP .ini configuration</h3>
<p>Now we need to make some changes to our php configuration file.  Leopard has an empty configuration file by default, but provides a file which you can use as a template.  From the terminal window, type:<br />
<code><br />
sudo cp /etc/php.ini.default /etc/php.ini<br />
</code><br />
Now, edit the <samp>/etc/php.ini</samp> file.  Find the <samp>include_path</samp> setting:<br />
<code><br />
;include_path = ".:/php/includes"<br />
</code><br />
And change it to<br />
<code><br />
include_path = ".:/usr/share/pear"<br />
</code><br />
This enables our PEAR installation.  You may also want to make some changes which will improve your ability to debug PHP.  FInd the line that says<br />
<code><br />
log_errors = Off<br />
</code><br />
and change it to<br />
<code><br />
log_errors = On<br />
</code><br />
You have to then restart Apache for these PHP changes to go into effect.</p>
<h3>Errors and Omissions</h3>
<p>Thats all there is to using the version of PHP delivered with OS X.  If you find this confusing, you are probably better off with something like XAMPP or MAMP.  I&#8217;ll probably end up compiling my own versions of PHP, but that is a different blog post.  I&#8217;ve already had problems with this configuration when I tried to install XDebug via PECL.  One last thing, if you run into problems, you can check the apache2 error_log file using the Console application.</p>
<p>For support, try the <a href="http://www.sitepoint.com/forums/">Sitepoint forums</a> or Apple&#8217;s <a href="http://discussions.apple.com/">Discussion Forums</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/feed/</wfw:commentRss>
		<slash:comments>230</slash:comments>
		</item>
	</channel>
</rss>
