<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Ramblings of a web guy</title>
        <description>Brian Moon, of dealnews.com, shares what he knows (and learns) about PHP, MySQL and other stuff</description>
        <link>http://brian.moonspot.net/feed.php?type=rss&amp;amp;tag=</link>
        <lastBuildDate>Sat, 19 May 2012 09:18:41 -0500</lastBuildDate>
        <generator>Wordcraft 0.10</generator>
        <item>
            <guid>http://brian.moonspot.net/prove-it-culture</guid>
            <title>Living in the Prove It Culture</title>
            <link>http://brian.moonspot.net/prove-it-culture</link>
            <description><![CDATA[Engineering cultures differ from shop to shop. I have been in the same culture for 13 years so I am not an expert on what all the different types are. Before that I was living in Dilbert world. The culture there was really weird. The ideas were never yours. It was always some need some way off person had. A DBA, a UI "expert" and some product manager would dictate what code you wrote. Creativity was stifled and met with resistance.<br><br>

I then moved to the early (1998) days of the web. It was a start up environment. In the beginning there were just two of us writing code. So, we thought everything we did was awesome. Then we added some more guys. Lucky for us we mostly hired well. The good hires where type A personalities that had skills we didn't have. They challenged us and we challenged them. On top of that, we had a CEO who had been a computer hacker in his teens. So, he had just enough knowledge to challenge us as well. Over the years we kept hiring more and more people. We always asked in the interview if the person could take criticism and if they felt comfortable defending their ideas. We decided to always have a white board session. We would ask them questions and have them work it out on a white board or talk it out with us in a group setting. The point of this was not to see if they always knew the answer. The point was to see how they worked in that setting. Looking back, the hires that did not work out also did not excel in that phase of the interview. The ones that have worked out always questioned our methods in the interview. They did not belittle our methods or dismiss them. They just asked questions. They would ask if we had tried this or that. Even if we could quickly explain why our method was right for us, they still questioned it. They challenged us.<br><br>

When dealing with people outside the engineering team, we subconsciously applied these same tactics. The philosophy came to be that if you came to us with an idea, you had to throw it up on the proverbial wall. We would then try to knock it down. If it stuck, it was probably a good idea. Some people could handle this and some could not. The ones that could not handle that did not always get their ideas pushed through. It may not mean they were bad ideas. And that is maybe the down side of this culture. But, it has worked pretty well for us.<br><br>

We apply this to technology too. My first experience on Linux was with RedHat. The mail agent I cut my teeth on was qmail. I used djbdns. When Daniel Beckham, our now director of operations, came on, he had used sendmail and bind. He immediately challenged qmail. I went through some of the reasons I prefered it. He took more shots. In the end, he agreed that qmail was better than sendmail. However, his first DNS setup for us was bind. It took a few more years of bind hell for him to come around to djbdns.<br><br>

When RedHat splintered into RedHat Enterprise and Fedora, we tried out Fedora on one server. We found it to be horribly unstable. It got the axe. We looked around for other distros. We found a not very well known distro that was known as the ricer distro of the Linux world called Gentoo. We installed it on one server to see what it was all about. I don't remember now whose idea it was. Probably not mine. We eventually found it to be the perfect distro for us. It let us compile our core tools like Apache, PHP and MySQL while at the same time using a package system. We never trusted RPMs for those things on RedHat. Sure, bringing a server online took longer but it was so worth it. Eventually we bought in and it is now the only distro in use here.<br><br>

We have done this over and over and over. From the fact that we all use Macs now thanks to Daniel and his willingness to try it out at our CEO's prodding to things like memcached, Gearman, etc. We even keep evaluating the tools we already have. When we decided to write our own proxy we discounted everything we knew and evaluated all the options. In the end, Apache was known and good at handling web requests and PHP could do all we needed in a timely, sane manner. But, we looked at and tested everything we could think of. Apache/PHP had to prove itself again.<br><br>

Now, you might think that a culture of skepticism like this would lead to new employees having a hard time getting any traction. Quite the opposite. Because we hire people that fit the culture, they can have a near immediate impact. We have a problem I want solved and a developer that has been here less than a year suggested that Hadoop may be a solution, but was not sure we would use it. I recently sent this in an email to the whole team in response to that.

<blockquote>The only thing that is *never* on the table is using a Windows server. If you can get me unique visitors for an arbitrary date range in milliseconds and it require Hadoop, go for it.</blockquote>

You see, we don't currently use Hadoop here. But, if that is what it takes to solve my problem and you can prove it and it will work, we will use it.<br><br>

Recently we had a newish team member suggest we use a SAN for our development servers to use as a data store. Specifically he suggested we could use it to house our MySQL data for our development servers. We told him he was insane. SANs are magical boxes of pain. He kept pushing. He got Dell to come in and give us a test unit. Turns out it is amazing. We can have a hot copy of our production database on our dev slices in about 3 minutes. A full, complete copy of our production database in 3 minutes. Do you know how amazing that is? Had we not had the culture we do and had not hired the right person that was smart enough to pull it off and confident enough to fight for the solution, we would not have that. He has been here less than a year and has had a huge impact to our productivity. There is talk of using this in production too. I am still in the "prove it" mode on this. We will see.<br>

<pre>I know you will ask how our dev db works, here you go:<br>
1. Replicate production over VPN to home office<br>
2. Write MySQL data on SAN<br>
3. Stop replication, flush tables, snapshot FS<br>
4. Copy snapshot to a new location<br>
5. On second dev server, umount SAN, mount new snapshot<br>
6. Restart MySQL all around<br>
7. Talk in dev chat how bad ass that is
</pre><br>

We had a similar thing happen with our phone system. We had hired a web developer that previously worked for a company that created custom Asterisk solutions. When our propietary PBX died, he stepped up and proved that Asterisk would work for us. Not a job for a web developer. But he was confident he could make it work. It now supports 3 offices and several home bound users world wide. He also had only been here a short time when that happened.<br><br>

Perhaps it sounds like a contradiction. It may sound like we just hop on any bandwagon technology out there. But no. We still use MySQL. We are still on 5.0 in fact. It works. We are evaluating Percona 5.5 now. We tried MySQL 5.1. We found no advantage and the Gentoo package maintainer found it to be buggy. So, we did not switch. We still use Apache. It works. Damn well. We do use Apache with the worker MPM with PHP which is supposedly bad. But, it works great for us. But, we had to prove it would work. We ran a single node with worker for months before trusting it. Gearman was begrudgingly accepted. The idea of daemonized PHP code was not a comforting one. But once you write a worker and use it, you feel like a god. And then you see the power. Next thing you know, it is a core, mission critical part of your infrastructure. That is how it is with us now. In fact, Gearman has went from untrusted to the go to tech. When someone proposes a solution that does not involve Gearman, someone will ask if part of the problem can be solved using Gearman and not whatever idea they have. There is then a discussion about why it is or is not a good fit. Likewise, if you want to a build a daemon to listen on a port and answer requests, the question is "Why can't you just use Apache and a web service?" And it is a valid question. If you can solve your problem with a web service on already proven tech, why build something new?<br><br>

This culture is not new. We are not unique. But, in a world of "brogramming" where "engineers" rage on code that is awesome before it is even working and people are said to be "killing it" all the time, I am glad I live in a world where I have to prove myself everyday. I am the most senior engineer on the team. And even still I get shot down. I often pitch an idea in dev chat and someone will shoot it down or point out an obvious flaw. Anyone, and I mean anyone, on the team can question my code, ideas or decisions and I will listen to them and consider their opinion. Heck, people outside the team can question me too. And regularly do. And that is fine. I don't mind the questions. I once wrote here that I like to be made to feel dumb. It is how I get smarter. I have met people that thought they were smarter than everyone else. They were annoying. I have interviewed them. It is hard to even get through those interviews.<br><br>

Is it for everyone? Probably not. It works for us. And it has gotten us this far. You can't get comfortable though. If you do foster this type of culture, there is a risk of getting comfortable. If you start thinking you have solved all the hard problems, you will look up one day and realize that you are suffering. Keep pushing forward and questioning your past decisions. But before you adopt the latest and greatest new idea, prove that the decisions your team makes are the right ones at every step. Sometimes that will take a five minute discussion and sometimes it will take a month of testing. And other times, everyone in the room will look at something and think "Wow that is so obvious how did we not see it?" When it works, it is an awesome world to live in.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Tue, 06 Mar 2012 22:45:18 -0600</pubDate>
            <category>mysql</category>
            <category>php</category>
            <category>programming</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/dev-hell-podcast-episode-5</guid>
            <title>/dev/hell Podcast Episode #5</title>
            <link>http://brian.moonspot.net/dev-hell-podcast-episode-5</link>
            <description><![CDATA[I was privileged to be invited to be a part of the <a href="http://devhell.info/post/2012-02-03/the-hammer-that-is-php/">/dev/hell podcast</a> this week. Thanks to Chris and Ed for having me on. Check it out. And subscribe to their podcast.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Fri, 03 Feb 2012 12:12:10 -0600</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/errors-adding-subtracting-dates</guid>
            <title>Errors when adding/subtracing dates using seconds</title>
            <link>http://brian.moonspot.net/errors-adding-subtracting-dates</link>
            <description><![CDATA[This just came up today again for me. I have said it before, but even I get lazy and forget. When doing math with dates such as adding days it is really quick to think this works:<br>
<pre>&lt;?php<br>
<br>
$date = "2011-11-01";<br>
<br>
// add 15 days<br>
<br>
$new_date = date("Y-m-d", strtotime($date) + (86400 * 15));<br>
<br>
// $new_date should be 2011-11-16 right?<br>
<br>
echo $new_date;<br>
<br>
?&gt;<br>
</pre>
This yields `2011-11-15`. The problem with this is that it assume that there are only 86400 seconds in every day. There are in fact not. On days when the clocks change for daylight savings time, there are either 1 hour more than that or 1 hour less than that. In addition, there are also <a href="http://en.wikipedia.org/wiki/Leap_second">leap seconds</a> put into our time system to keep us in line with the sun. There is one this year, 2012, on June 30th in fact. Since they don't happen with the regularity that daylight savings time does, it may be easy to forget those. Luckily, for this problem, the solution is the same. You have two choices. And the solution you choose depends on the particular problem you have. For the simple problem above, you can simply let strtotime take care of it for you.<br>
<pre>$new_date = date("Y-m-d", strtotime($date." +15 days"));
</pre>
<a href="http://php.net/strtotime">strtotime()</a> is the most awesome date/time related function in all of computer programming. I have <a href="http://brian.moonspot.net/2008/09/20/strtotime-the-php-date-swiss-army-knife/">written about</a> it before. It handles all those nasty weird seconds issues. But, if you are not solving a problem this simple or you are reading this and need help with another language, there is another solution. You do all your date math at noon. Simply only run code that does date math during lunch time. No, just joking. That would be silly. What I mean is to adjust all your date/time variables to represent the time at 12:00 hours.<br>
<pre>$new_date = date("Y-m-d", strtotime($date." 12:00:00") + 86400 * 15);<br>
</pre>
Now that you are doing date math at noon, you will be safe for most any date range you are doing math on. Daylight savings time always gives and hour and takes an hour every year, so those cancel each other out. It would take a whole lot of leap seconds to cause the offset from the start date to the end date to shift enough to make this technique no longer work, but it is technically feasible. So, if you are adding hundreds of years to dates, this won't work for you. There, disclaimer added.<br><br><strong>UPDATE</strong>: I should point out that the examples in this post only apply to US time zones that recognized Daylight Savings Time and the rules for DST as they apply after the changes in 2007.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Mon, 16 Jan 2012 15:55:49 -0600</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/google-not-sending-referrers</guid>
            <title>Google is breaking the Web</title>
            <link>http://brian.moonspot.net/google-not-sending-referrers</link>
            <description><![CDATA[So, Google <a href="http://googleblog.blogspot.com/2011/10/making-search-more-secure.html">announced today</a> that they would start doing a couple of new things. First, they are going to start sending all logged in users to their SSL enabled search page. Secondly, they claimed they are going to stop sending search terms to the sites in the referring URL. They claim all of this for your security. The first one I buy. SSL is better for those people on public wifi, no doubt. The second, I don't think so.<br><br>Let's back up a step. For those that don't know how the web works, this is a quick lesson. When you click on a link on a site, your browser connects to that new site to get the page. Part of that communication is to tell the site you are going to what site the user was on when they clicked on your URL. This is a good thing. There is never any information passed between Google and your site. Its all between your browser on your computer and the site you are asking your compter to load. It helps site owners know who is linking to them. In the case of search engines, the referring URLs often contain the search terms someone typed in to find their site. This is also helpful for lots of reasons. None of them involve a user's security.<br><br>Ok, so, Google claims they are going to remove your search terms. But, my tests show they are removing the whole referring URL. Yes, you will not know what users are coming from Google. Let me show you. This is what I did.<br><ol><li>I typed http://www.google.com/ into my browser</li><li>I searched for dealnews</li><li>I clicked on the first link, which is the dealnews.com front page.</li></ol></li>Using a tool called <a href="https://addons.mozilla.org/en-US/firefox/addon/httpfox/">HTTPFox</a> I am able to see what information is being passed between my computer and the web sites. This is what I see:<br><ol><li>http://www.google.com/ with no referring URL</li><li>http://www.google.com/#hl=en&sugexp=kjrmc&cp=5&gs_id=j&xhr=t&q=dealnews&qe=ZGVhbG4&qesig=YtB_HodN2qCOIiqwx_wetA&pkc=AFgZ2tlle01GJ99f38Ol-HvrY0sbiq4vzJfAPDSXGQ2js5QqyHGJ9-5HIgoFXbUujrU81pfyhEVO8jpmFouC09MG1fRbqd0GVA&pf=p&sclient=psy-ab&site=&source=hp&pbx=1&oq=dealn&aq=0&aqi=g4&aql=f&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=7b65204da701ddb7&biw=1295&bih=1406 with no referring URL because Google use javascript to load the search results.</li><li>http://www.google.com/url?sa=t&source=web&cd=1&sqi=2&ved=0CCwQFjAA&url=http%3A%2F%2Fdealnews.com%2F&rct=j&q=dealnews&ei=EPOdTtaUN4XOiAKZlIntCQ&usg=AFQjCNEN2YJ8XgSAJm6FOUqK2PuBUOkfxA&sig2=N2jBSsJb8sgPsrTkGgFCfw&cad=rja with a referrring URL of http://www.google.com/</li><li>http://dealnews.com/ with a referring URL of http://www.google.com/url?sa=t&source=web&cd=1&sqi=2&ved=0CCwQFjAA&url=http%3A%2F%2Fdealnews.com%2F&rct=j&q=dealnews&ei=EPOdTtaUN4XOiAKZlIntCQ&usg=AFQjCNEN2YJ8XgSAJm6FOUqK2PuBUOkfxA&sig2=N2jBSsJb8sgPsrTkGgFCfw</li></ol></li>As you can see, the request to http://dealnews.com/ was sent a URL by my browser telling that site that Google was linking to dealnews. In that URL you will see q=dealnews. That is the search term I typed into Google. Now, lets see what happens when I do the same thing on SSL.<br><ol><li>https://www.google.com/ with no referring URL</li><li>Redirected to https://encrypted.google.com/ with no referring URL</li><li>https://encrypted.google.com/#hl=en&sugexp=kjrmc&cp=8&gs_id=f&xhr=t&q=dealnews&tok=wzChADhZTTjwPuXR1iOwSA&pf=p&sclient=psy-ab&site=&source=hp&pbx=1&oq=dealnews&aq=0&aqi=g4&aql=f&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=47f2f62d0e6da959&biw=1295&bih=1406 with no referring URL because Google use javascript to load the search results.</li><li>https://encrypted.google.com/url?sa=t&source=web&cd=1&sqi=2&ved=0CCsQFjAA&url=http%3A%2F%2Fdealnews.com%2F&rct=j&q=dealnews&ei=x_edTvjlGeKviQKzmdHqCQ&usg=AFQjCNEN2YJ8XgSAJm6FOUqK2PuBUOkfxA&sig2=OEhW8Z_BhHcCboIzu_Z2zQ with a referring URL of https://encrypted.google.com/</li><li>http://dealnews.com/ with no referring URL.</li></ol></li>So, if dealnews.com does not get a referring URL, how do we know this came from Google. This is the quote from the Google blog post:<em><br></em><blockquote><em>When you search from <a href="https://www.google.com/">https://www.google.com</a>,
 websites you visit from our organic search listings will still know 
that you came from Google, but&nbsp;won't receive information about each 
individual query. </em><br></blockquote>I ask you how the site will know that if there is no referring URL? Referring URLs are a fundamental part of the web. If Google wants to strip data off the URL, that is one thing. It is not great IMO, but whatever. But, not sending referrers at all is&nbsp; just wrong and should be changed.<br><br>If you care, please share this post. Tweet it, +1 it, whatever. This is just bad news for the web.<br><br><strong>Edit:</strong> I wanted to make sure everyone knew, I observed the same behavior in both Firefox 7 and latest Google Chrome<br><br><strong>Edit 2:</strong> I have also confirmed with the Apache access logs that no referring URL was sent.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Tue, 18 Oct 2011 17:09:05 -0500</pubDate>
            <category>google</category>
            <category>http</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/lightbox-using-yui</guid>
            <title>Lightbox using YUI</title>
            <link>http://brian.moonspot.net/lightbox-using-yui</link>
            <description><![CDATA[I made this a while back but have not blogged about it. I needed a <a href="http://en.wikipedia.org/wiki/Lightbox_%28JavaScript%29">lightbox</a> for a project. So, I looked around. Like usual, none of them were right for me. In addition to that, I am not on the jQuery band wagon. No particular reason. I just never latched on to the weird syntax (They made a function named $ so it could kind of sort of read like PHP, come on). Anyhow, not a jQuery hate post. I did however take a liking to <a href="http://developer.yahoo.com/yui/">YUI</a>. It is more my style. Less magic stuff and more of a real library. I feel like I can use it where I need to and not use it when I don't. Again, not a YUI love fest post. Long story short, I chose to make my lightbox with the help of YUI. I have just uploaded <a href="https://github.com/brianlmoon/yui2_lightbox">the code</a> to GitHub. Maybe someone else will find it useful. I have an <a href="http://brian.moonspot.net/lightbox/">example page</a> as well.<br><br><strong><span>Features</span></strong>
   <ul><li>Lightbox and contents can be created via:
     <ul><li>Javascript</li><li>Existing markup</li><li>Asynchronus (AJAX) request (contents only)</li></ul>    </li><li>Lightbox will close when ESC is pressed</li><li>Rounded corners and box shadow using CSS3</li><li>Exposes an onClose event that can be subscribed to</li></ul>   <p>
   </p><strong><span>Compatibility</span></strong>
   <ul><li>Firefox 3.5+</li><li>Chrome 4+</li><li>Safari 5+</li><li>Internet Explorer 9 (Animation is not working due to YUI's lack of opacity support in IE9)</li><li>Internet Explorer 8 (Via IE9 in IE8 compatibility mode. No rounded corners, no shadows)</li><li>Internet Explorer 7 (Via IE9 in IE7 compatibility mode. No rounded corners, no shadows)</li><li>Opera 10.53</li></ul>   <strong><span></span></strong><strong><span>YUI Requirements</span></strong>
   <ul><li>Dom</li><li>Event</li><li>Connection Core</li><li>JSON</li><li>Selector</li><li>Animation (if animate set to true)</li></ul>]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Sun, 04 Sep 2011 20:53:55 -0500</pubDate>
            <category>javascript</category>
            <category>yui</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/tty-or-interactive-terminal-in-php</guid>
            <title>Check for a TTY or interactive terminal in PHP</title>
            <link>http://brian.moonspot.net/tty-or-interactive-terminal-in-php</link>
            <description><![CDATA[Many UNIX tools do different things if they are connected to an interactive terminal, also called a <a href="http://www.linusakesson.net/programming/tty/index.php">TTY</a>. This can be handy for lots of reasons. I had a use case today that prompted me to find out how to do it in PHP.<br><br>Here is the situation. We log errors to the PHP error log. We then have processes that monitor that error log and alert us about any uncaught exceptions or fatal errors very quickly so we can address issues. We also monitor non-fatal errors and alert on those on a less frequent schedule. However, this can be annoying if a user is running some code on a terminal that is generating errors. Let's say I am trying to find out why some file import did not happen. Running the job that is supposed to do it may yield an error. Maybe it was a file permission issue or something. There are other people watching the alerts. What they don't know is that I am running the code and looking at these errors in real time. So, they may start digging into the issue when I am the one causing it and can see it happening already. So, I thought it would be nice, if in my error handler, I could not send errors to the error log that are being sent to an interactive terminal. A few quick searches for "php check for tty" did not find anything. In the end, a coworker cracked open a book to see how it was done in C. That got me on the right path to finding two PHP functions: <a>posix_isatty</a> and <a href="http://www.php.net/posix_ttyname">posix_ttyname</a>. These seem to do the trick. They take a file descriptor like STDOUT and will tell you if that is an interactive terminal and what the tty name is if it is one.<br><br>It took me a few tries to get the full effect I wanted in PHP. The thing I always forget is that fatal errors don't use my error handler. I understand why. The engine is in an unknown state when that happens, so it can't keep running code. In the end I added this code to my <a href="http://us3.php.net/manual/en/ini.core.php#ini.auto-prepend-file">auto prepend file</a> which is where my error handler, auto loader and other start up stuff is defined for all PHP code we run, both CLI and Apache. Since PHP will send errors to STDERR if it is defined, that is what we want to check for. If it is defined and it is a TTY, we just disable error logging. I should note that I already check the log_errors ini setting in my error handler before I even call the error_log function. <br>

<pre>if(defined("STDERR") && posix_isatty(STDERR)){<br>
&nbsp;&nbsp;&nbsp;&nbsp;ini_set("log_errors", false);<br>
&nbsp;&nbsp;&nbsp;&nbsp;ini_set("error_log", null);<br>
}
</pre>Hopefully anyone else searching for "php check for tty" or "php interactive terminal" will find this blog post and it will help them out.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 01 Sep 2011 23:42:54 -0500</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/gearman-nyc-etsy</guid>
            <title>Talking about Gearman at Etsy Labs</title>
            <link>http://brian.moonspot.net/gearman-nyc-etsy</link>
            <description><![CDATA[I find myself flying to New York on Monday for some <a href="http://dealnews.com/">dealnews</a> related business. Anytime I travel I try and find something fun to do at night. (Watching a movie by myself in Provo, Utah was kinda not that fun.) So, this week I asked on Twitter if anything was happening while I would be in town. Anything would do. A meetup of PHP/MySQL users or some design/css/js related stuff for example. Pretty much anything interesting. Well, later that day I received an IM from the brilliant <a href="https://twitter.com/allspaw">John Allspaw</a>, Senior VP of Technical Operations at <a href="http://www.etsy.com/">Etsy</a>. He wanted me to swing by the Etsy offices and say hi. Turns out it is only a block away from where I would be. Awesome! He also mentioned that he would like to have me come and speak at their offices some time. That would be neat too. I will have to plan better next time I am traveling up there.<br><br>Fast forward another day. I get an email from <a href="https://twitter.com/kellan">Kellan Elliott-McCrea</a>, CTO of Etsy wanting to know if I would come to the Etsy offices and talk about Gearman. At first I thought "That is short notice, man. I don't know that I can pull that off." Then I remembered the last time I was asked to speak at an event on short notice based off a recommendation from John Allspaw. <br><br>It was in 2008 for some new <a href="http://brian.moonspot.net/2008/06/18/did-you-know-i-am-going-to-be-at-velocity/">conference called Velocity</a>. That only turned out to be the best conference I have ever attended. I have been to Velocity every year since and this year took our whole team. In addition, I spoke again in 2009 at Velocity, wrote a chapter for John's book <a href="http://www.amazon.com/Web-Operations-Keeping-Data-Time/dp/1449377440/ref=sr_1_1?ie=UTF8&qid=1312548595&sr=8-1">Web Operations</a> that was released at Velocity in 2010 and was invited to take part in the Velocity Summit this year (2011) which helps kick off the planning for the actual conference. The moral of that story for me is: when John Allspaw wants you to take part in something, you do it.<br><br>In reality, it was not that tough a decision. Even without John's involvement, I love the chance to talk about geeky stuff. The Etsy and dealnews engineering teams are like two twins separated at birth. Every time we compare notes, we are doing the same stuff. For example, we have been trading Open Source code lately. They are using my <a href="https://github.com/brianlmoon/GearmanManager">GearmanManager</a> and we just started using their statistics collection daemon, <a href="https://github.com/etsy/statsd">statsd</a>. So, speaking to their people about what we do seem like a great opportunity to share and get input.<br><br>The event is open to the public. So, if you use Gearman, want to use Gearman, or just want to hear how we use Gearman at dealnews, come here me ramble on about how awesome it is Tuesday night in Dumbo at Etsy Labs. You can RSVP on the <a href="http://codeascraftgearman.eventbrite.com/">event page</a>.<br><br><a style="font-family: yui-tmp;" href="http://codeascraftgearman.eventbrite.com/"><a href="http://codeascraftgearman.eventbrite.com/"></a></a><a>Best Practices for Gearman by Brian Moon</a><br>Etsy Labs<br>55 Washington St. Ste 712<br>NY 11222<br><br>Tuesday, August 09, 2011 from 7:00 PM - 10:00 PM (ET)]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Fri, 05 Aug 2011 08:11:16 -0500</pubDate>
            <category>devops</category>
            <category>gearman</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/personal-day</guid>
            <title>Taking a personal day</title>
            <link>http://brian.moonspot.net/personal-day</link>
            <description><![CDATA[I mostly talk about geeky stuff on this blog, but sometimes I like to get a little more personal. Today is one of those days.<br><br>Like this post, I took my public speaking to a personal place this month. At the Ignite Birmingham event this month I decided to talk about what life is like with a large family. This was a different experience for me. It was very well received and my wife was there to watch it. She had not seen the slides so it was a surprise to her. Here is the <a href="http://www.youtube.com/user/ignitebirminghamal#p/u/6/oKAiPaH3BF8">video</a>.<br><br>My daughter's 8th grade class had a "graduation" ceremony on Tuesday. Now, I kind of think that is a bit silly. I approached as an awards ceremony. They give out awards for best GPA per core class. They also award student athletes of each sport. the SGA and drama department are honored. I think those are all great things. Well, Macy, my 13 year old received seveal honors. If I told you I did not expect them I would be lying. She was a head cheerleader, class historian/photographer, played the lead role in the school play and is an all around good student. She received awards for all of those things. Those were expected. After the students all walked across the stage, the vice principal and principal had one more award to give. Each of them chooses one boy and one girl based on their own criteria to receive the Vice Principal's Award and Principal's Award. We sat listening to the principal talk about who she chose the students to receive the award. She spoke of character, kindness, school spirit, work ethic and all the qualities that one hopes their child has. Then, much to our surprise, she says Macy's name. I was floored. I admit, while she was saying all those things, I was thinking "Macy fits all those to a T, she should get that, but probably won't". I figured it would go to some goody two shoes kid I had never met because their mom was always helping out at the school and they would always chat it up with the principal in the hallways. In reality, my wife and I have not always seen eye to eye with the principal and I feared that relationship would also be a hurdle. But, no, kudos to the principal. She evaluated Macy for being Macy. And I won't lie, that will probably help the relationship between myself and the principal as my other kids go into that school.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 26 May 2011 12:57:23 -0500</pubDate>
            <category>personal</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/php-frameworks</guid>
            <title>PHP Frameworks</title>
            <link>http://brian.moonspot.net/php-frameworks</link>
            <description><![CDATA[Last week I spoke at and attended the first ever <a href="http://www.phpcon.org/">PHP Community Conference</a>. It was very good. It was also very different from my normal conference. I usually go for very technical stuff. I don't often stop and smell the roses of the community or history of my chosen (by me or it I am not sure sometimes) profession. There was a lot of community at this one.<br><br>One thing that seemed to be a hot topic at the conference was frameworks. <a href="http://cakedc.com/">CakeDC</a>, the money behind <a href="http://cakephp.org/">CakePHP</a> was the platinum sponsor. I chatted with <a href="http://twitter.com/phpnut">Larry Masters</a> the owner of CakeDC for a bit while walking one night. Great guy. <a href="http://twitter.com/jperras">Joël Perras</a> gave a tutorial about <a href="http://lithify.me/">Lithum</a>. I attended most of this one. He did very well. Joël was frank and honest about the benefits and problems with using frameworks, including having to deal with more than one at a time. There was also a tutorial about Zend Framework patterns by <a href="http://weierophinney.net/matthew/">Matthew Weier O'Phinney</a>. I missed this one. On the second day, things were different. <a href="http://twitter.com/rasmus">Rasmus Lerdorf</a> warned about the bloat in most of the PHP frameworks and expressed hope that they would do better in the newer versions. I received several questions about frameworks in my session. I also spoke out about them a bit. <a href="http://twitter.com/tychay">Terry Chay</a> wrapped up the day with his closing keynote and touched on them again. More on that later. I want to kind of summarize what I said (or meant to say).<br><br><strong>PHP is a framework</strong><br><br>In my session, I talked about the history of <a href="http://www.phorum.org/">Phorum</a>. One of the things I covered was the early days of PHP. Back in the 90s, before PHP, most dynamic web work was done in C or Perl. At that time, in those worlds, you had to do all the HTTP work yourself. If you wanted a content type of text/html, you had to set it, in code, on every single response. Errors in CGI scripts would often result in Apache internal error pages and made debugging very hard. All HTML work had to be done by writing to output. There was no embedding code with HTML even as a templating language. PHP changed all that. You had a default content type of text/html. You had automatic handling of request variables. Cookies were easily ingested and output. You could template your HTML with script instead of having to write everything out via print or stdout. It was amazing. Who could ask for more?<br><br><strong>Frameworks as a tool</strong><br><br>Well, apparently a world that I honestly don't work in could ask for more. There are three major segments of web developers these days. There are developers that work for a company that has a web site, but its business is not the web site. Maybe it is a network hardware company or some other industry where their business merits having a staff to run their site, but it is not their core business. Then there are developers like myself that work for a company where the web site is the business. Everything about the business goes through the web. We have the public web site and the internal web site our team uses. It is everything. The last type are those developers that are constantly building new sites or updating existing sites for clients. I will be honest, this is not a segment I have considered much in the past when writing code or blog posts. But, I met more of those people at this conference than any of the other two types. They seem to be the ones that are motivated and interested. Or at least, because PHP and the web are their business, they sent their people to the conference. <br><br>You see, I have spoken out about frameworks. Not very publicly, but those that know me have heard me comment about them. I have never really seen the point. Why start with something generic that will most likely not fit your ultimate need when you need to scale or expand beyond its abilities? Well, for thousands of web sites, that are likely being built by agencies, that time never occurs. Most likely, before that happens, the site will be redesigned and completely replaced. So, if you spend every day building a new site, why do all that groundwork every time? <br><br>In addition, why have to deal with every different client's needs? I often say that Apache is my <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller">controller</a>. I don't like to use PHP as my controller. But, if I was deploying a site every week to a different stack, I can't rely on Apache with mod_rewrite or whatever things I rely on in my job today. So, you need to have full control in the application. What database will the client this week use? I don't care, the framework abstracts that for me. These are all very good reasons to use a framework.<br><br><strong>Framework Trade-Off</strong><br><br>There are some trade-offs though. The biggest one I see is the myriad of choices. Several of the pro-framework people even mentioned that there are a lot out there. And it seems that someone is making a new one everyday. With all these choices, it is likely that some of the benefit you get from a framework could be lost. If a client already has a site based on CakePHP and your agency uses Lithium what do you do? Say no to the work or have to deal with the differences? Some of them are big enough to be a real issue. Some are so small, you may not notice them until it's too late. That is a tough place to be.<br><br>The other issue is performance. Frameworks are notoriously inefficient. It has just been their nature. The more you abstract away from the core, the less efficient you are. This is even true with PHP. Terry Chay pointed out that PHP is less efficient than Java or C in his keynote. But, you gain power with PHP in way of quicker development cycles. Frameworks have that same benefit. But, have not solved this issue any better than PHP has over C. They abstract away the low level (for PHP at least) stuff that is going on. And that means loss of efficiency. This can be solved or at least worked on, however, and I hope it is.<br><br><strong>Frameworks as a Commodity</strong><br><br>So, this gets me back to something Terry Chay said. He talked about the motivation of companies to open source their technology. He used Facebook's <a href="http://www.facebook.com/notes/facebook-engineering/building-efficient-data-centers-with-the-open-compute-project/10150144039563920">Open Compute Project</a> as an example. He pointed out that a major reason Facebook would open up this information would be in hopes that others would do the same in their data centers. If that happened, it would be easier for Facebook to move to a new data center because it was already mostly setup the way they like it.<br><br>Transitioning this same thought frameworks, the commoditization here, that I see, is in the interest of developers. If the framework you support becomes the de facto standard, then all those developers working in agencies using it are now ready to come to work for you. Plus, if you are the company behind it, there are opportunities for books, conferences, training, support, and all the other peripherals that come from the commercial/open source interaction. Need proof of that? Look no further than the "PHP Company", Zend. They could have committed developers to PEAR, but instead created Zend Framework. I see job listings very often for Zend Framework experience. Originally Zend tried to monetize the server with their optimizers and Zend Server. They had moderate success. The community came up with <a href="http://php.net/manual/en/book.apc.php">APC</a> and <a href="http://xcache.lighttpd.net/">XCache</a> that sort of stole their thunder. I feel they have had much better success with Zend Framework in terms of market penetration. The money is with the people that write the code, not run the servers.<br><br><strong>Frameworks are EVERYWHERE</strong><br><br>I will close with something else that Terry Chay said. This was kind of an aha! moment for me. Terry pointed out that frameworks are everywhere. Wordpress, Drupal and even my project, <a href="http://www.phorum.org/">Phorum</a>, are frameworks. You can build a successful site using just those applications. It is not just the new breed code libraries that can be viewed as frameworks. In fact, Phorum's very own Maurice Makaay is building his new web site using only Phorum 5.3 (current development branch). Phorum offers easier database interaction, output handling, templating, a pluggable module system and even authentication and group based permissions. Wow, I have always kind of shunned this idea. In fact, when Maurice first showed me his site, I kind of grimaced. Why would you want to do that? You know why? Because the main thing that drives his site is Phorum. His users come to the site for Phorum. So, why would he want to install Phorum, invest in making it all it can be and then have to start from scratch for all the other parts of the site that are not part of the message board. Duh, I kind of feel stupid for never looking at things from this perspective before. Feeling dumb is ok. I get smarter when I feel dumb. New ideas make me a better developer. And I hope that is what comes out of this experience for me. You never know, I may throw my name in this hat and see how Phorum's groundwork could be useful outside of the application itself.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Mon, 25 Apr 2011 10:00:00 -0500</pubDate>
            <category>mysql</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/experimenting-with-html5</guid>
            <title>HTML5 Experiment</title>
            <link>http://brian.moonspot.net/experimenting-with-html5</link>
            <description><![CDATA[I was looking through <a href="http://dealnews.com/">dealnews.com</a> browser stats the other day to see how many of our visitors had browsers that could use CSS3. This was how it broke down.<br>
<br><img  alt="" style="width: 301px; height: 232px;" src="http://content.screencast.com/users/brianlmoon/folders/Jing/media/89e5dadf-2ed2-498d-a44f-3f4f8e2935b4/00000442.png"><br>
<br>
58% of dealnews visitors have browsers that support some CSS3 elements like border-radius and box-shadow. This includes recent Webkit, Firefox 3.5+, Opera 10+ and IE9. Awesome! Another 37% fully support CSS2. This includes IE7, IE8 and Firefox 2 - 3.0.x. <br><br>We have started to sneak in some CSS3 elements into the CSS on <span>dealnews.com</span>. In places where rounded corners are optional (like the <a href="../lightbox/">lightbox</a>
 I created), we use border-radius instead of a lot of images. The same 
for shadows. We have started using box-shadow instead of, well, nothing.
 We just don't have shadows if the browser does not support box-shadow. 
In our recent redesign of our mobile site, we used all CSS3 for shadows,
 corners and gradients. But these were all places where things were 
optional. <br><br>The header of dealnews.com, on the other hand, requires a certain consistency. It 
is the first thing you see. If it looks largely different on your work 
computer running IE7 than it does on your Mac at home using Safari, that may be 
confusing. So, we have stuck with images for rounded 
corners, shadows and gradients. The images have problems though. On the iPad for 
instance, the page starts zoomed out a bit. The elements holding the 
rounded corner images don't always line up well at different zoom 
levels. Its a math thing. When zooming, you end up with an odd number of
 pixels at times which causes pixels to shift. So, we get gaps in our 
tabs or buttons. Not pretty. This has been bugging me, but its really 
just the iPad. Its not mission critical to fix a pixel on the iPad. Armed with the numbers above, I decided to try and reproduce the dealnews.com header using the most modern techniques possible and see how well I could degrade the older browsers.<br>
<br>
Here is a screen shot in Firefox 4 of the current dealnews header. (You can click any of these images to see them full size.)<br><br>
<a href="/html5exp/current.png"><img  alt="" style="width: 600px;" src="/html5exp/current.png"></a><br>
<br>
Now, here is the HTML5/CSS3 header in all the browsers I tried it in. I developed in Firefox 4 and tested/tweaked in others.<br>
<br>
<strong>Firefox 4 (Mac)</strong><br>
<a href="/html5exp/ff4.png"><img  alt="" style="width: 600px;" src="/html5exp/ff4.png"></a><br>
<br>
<strong>Firefox 3.6 (Windows)</strong><br>
<a href="/html5exp/ff3.png"><img  alt="" style="width: 600px;" src="/html5exp/ff3.png"></a><br>
<br>
<strong>Chrome 10</strong><br>
<a href="/html5exp/webkit.png"><img  alt="" style="width: 600px;" src="/html5exp/webkit.png"></a><br>
<br>
<strong>Opera 11</strong><br>
<a href="/html5exp/opera11.png"><img  alt="" style="width: 600px;" src="/html5exp/opera11.png"></a><br>
<br>
<strong>Internet Explorer 9</strong><br>
<a href="/html5exp/ie9.png"><img  alt="" style="width: 600px;" src="/html5exp/ie9.png"></a><br>
<br>
<strong>Internet Explorer 8 (via IE9 Dev Tools)</strong><br>
<a href="/html5exp/ie8.png"><img  alt="" style="width: 600px;" src="/html5exp/ie8.png"></a><br>
<br>
<strong>Internet Explorer 7 (via IE9 Dev Tools)</strong><br>
<a href="/html5exp/ie7.png"><img  alt="" style="width: 600px;" src="/html5exp/ie7.png"></a><br>
<br>
<strong>Internet Explorer 6 (ZOMG!!1!)</strong><br>
<a href="/html5exp/ie6.png"><img  alt="" style="width: 600px;" src="/html5exp/ie6.png"></a><br>
<br>
Wow! This turned out way better than I expected. Even IE6 renders nicely. I did have to degrade in some older versions of Internet Explorer. This gets me 97% coverage for all the dealnews.com visitors. And, IMO, degrading this way is not all that bad. I am seeing it more and more around the internet. CNET is using border-radius and CSS3 gradients in their header. In Internet Explorer you see square corners and no gradient. Let's look a little deeper into what I used here.<br>
<br>
<strong>Rounded corners</strong><br>
<br>
For all the rounded corners, I used a border-radius of 5px. I used CSS that would be most compatible. For border-radius that means a few lines just to get the one effect across browsers. The CSS for the tabs looks like this.<br>
<br>
<code>
-moz-border-radius-topleft: 5px;<br>-moz-border-radius-topright: 5px;<br>border-top-left-radius: 5px;<br>border-top-right-radius: 5px;
</code>
<br>
<br>The -moz is to support Firefox 3.5+. Everything else that supports border-radius recognizes the non-prefixed style.<br>
<br>
For the older browsers, they just use square corners. I think they still look nice. The one thing we lose with this solution is the styled gradient border on the brown tabs. It fades to a silver near the bottom of the tabs. There is no solution for that in CSS at this time. That is a small price to pay to skip loading all those images IMO.<br>
<br>
<strong>Shadows</strong><br>
<br>
For the shadows on the left and right side of the page (sorry, not real visible in the screen shots), I used box-shadow. This requires CSS such as:<br>
<br>
<code>
-webkit-box-shadow: 0 0 0 transparent, 0 2px 2px #B2B1A6;<br>-moz-box-shadow: 0 0 0 transparent, 0 2px 2px #B2B1A6;<br>box-shadow: 0 0 0 transparent, 0 2px 2px #B2B1A6;
</code>
<br>
<br>Again, -moz for Mozilla browsers and -webkit for WebKit based browsers. Now, there are some gotchas with box-shadow. The first is that Firefox requires a color. The other supporting browsers will simply use an alpha blended darker gradient. This makes it a little more work to get it all right in Firefox. The other tricky part was getting the vertical shadow to work. The shadow you make actual curves around the entire element. It has the same z-index as the element itself. So, a shadow on an element will appear on top of other elements around it with a lower z-index. I had issues keeping the shadow from the lower area (the vertical shadow) from appearing above the element and on top of the tabs. If you look really, really, really close where the vertical and horizontal shadows meet, you will see a tiny gap in the color. Luckily for me, it works due to all the blue around it. That helps mask that small flaw.<br>
<br>
For the older IE browsers, I used <a href="http://msdn.microsoft.com/en-us/library/ms537512%28v=vs.85%29.aspx">conditional IE HTML</a> blocks and added a light gray border to the elements. It is a bit more degraded than I like, but as time passes, those browsers will stop being used.<br><br><strong>Gradient Backgrounds</strong><br><br>Completing the holy trinity of CSS3 features that make life easier is gradient backgrounds. This is the least unified and most complex of the three features I have used in this experiement. For starters, no two browser use the same syntax for gradient backgrounds. Firefox does use the W3C recommended syntax. Webkit uses something they came up with and Internet Explorer uses its super proprietary filter CSS property and not the background property. The biggest problem with the filter property is that it makes IE9 not work with border-radius. The tabs could not use a gradient in IE9 because it applied a rectangular gradient to the element that exceeded the bounds of the rounded top corners. Bummer. Once the standard is set this should all clear itself up. As things stand today, I had to use the following syntax for the shadows.<br>
<br>
<code>
background: #4b4ba8; /* old browsers */<br>
background: -moz-linear-gradient(top, #4b4ba8 0%, #3F3F9A 50%, #303089 93%); /* firefox */<br>
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4b4ba8), color-stop(50%,#3F3F9A), color-stop(93%,#303089)); /* webkit */<br>
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4b4ba8', endColorstr='#303089',GradientType=0 ); /* ie */
</code>
<br>
<br>
As you can see, this is pretty complex. See the next section for a quick way to configure that block of CSS.<br><br>Another thing that makes working with these gradients more complex than images is a lack of rendering control. When you are making images, you can control the exact RGB values of the colors in the images. When you leave it up to the browser to render the gradient, sometimes they don't agree. I had to do a lot of fiddling with the RGB values to get all the browsers to render the gradient just right. Some of this had to do with the short vertical area I am using in the elements. That limits the number of colors that can be used to make the transition. So, just be careful when you are lining up two elements with gradients that transition from one element to the other like I have here with the blue tab and the blue navigation bar.&nbsp; <br>
<br><strong>CSS3 Online tools</strong><br><br>Remembering all the CSS3 syntax is a little daunting. Luckily, there are some cool online tools to generate some of this stuff. Here are few I have used.<br><br><ul><li><a href="http://css3generator.com/">CSS3 Generator</a> - This tool can generate lots of different CSS3 effects.</li><li><a href="http://border-radius.com/">CSS3 Border Radius Generator</a> - This tool only generates border radius, but lets you set each corner individually.</li><li><a href="http://www.colorzilla.com/gradient-editor/">Ultimate CSS Gradient Generator</a> - This is a great tool that lets you generate gradient backgrounds and even supports Internet Explorer compatible background gradients.</li></ul><br>
<strong>HTML5 Elements</strong><br>
<br>
To make this truly an HTML5 page, I wanted to use the new doctype and some of the new elements. I make use of the &lt;header&gt; and &lt;nav&gt; tags in this page. The &lt;header&gt; tag is just what you would think it is. It surrounds your header. This is all part of the new semantic logic behind HTML 5. The &lt;nav&gt; tag surrounds major site navigation. Not just any navigaion, major navigation. The <a href="http://html5doctor.com/nav-element/">HTML5 Doctor</a> has more on that.<br>
<br>
To make IE support them, I used a bit of javascript I found on the internet along with some CSS to set them to display as block level elements. The CSS is actually used by older Firefox versions as well.<br>
<br>
<strong>A couple of non-CSS3 techniques</strong><br>
<br>I did a couple of things that are not CSS3 or HTML5 in this page. One is that I put the CSS into the page and not in its own file. With modern broadband, the biggest issue in delivering pages fast is the
 number of HTTP requests, not (always) the total size of the data. The 
more HTTP requests required to start rendering your page, the longer it 
will take. Your optimization goals will determine if this technique is right for you. I currently include all CSS needed to render the header in the page so that the rendering can start without any additional HTTP requests. The CSS for the rest of the page is included via a link tag.<br><br>The other technique I used in this page that is not new, but is not widely used. Again, depending on your needs, it may be a possible win when trying to reduce HTTP requests. I used <a href="http://en.wikipedia.org/wiki/Data_URI_scheme#CSS">embedded image data URIs</a> in the CSS for the three images I still needed for this page. Basically, you base64 encode the actual image file and put it into the CSS. The benefit is that this page is fully rendered with just one HTTP request. The downside is that the base size for the page (or CSS if it is external) that has to be downloaded every time is much larger. Probably a good compromise would be to put the CSS into an external file. This would mean just two HTTP requests would be needed and the CSS could be cached. For IE6, I just used conditional HTML to include an actual URL to the background images.<br>
<br>
Th data URI technique is a little bit of a mysterious technique in that it does make for a larger page, but can help with render time on first load. This really comes down to what you are optimizing for. If you are optimizing for repeat visitors, it may be that the images are better off being separate requests. If you are optimizing for new visitors, this technique will yield a faster rendering page. In Chrome and IE9, the onLoad event fired much sooner (as much as half the time) using this technique than having the images as a separate reqeust. In Firefox, something else is going on. I am not sure what. The onLoad event still fires sooner, but not a whole lot sooner. The DOMContentLoaded event in Firefox however fires later with this technique than with the images in a separate request. Firefox was the only browser that showed this pattern.<br>
<br><strong>OOCSS</strong><br><br>It is not really HTML5 or CSS3 related, but I do want to give some credit to <a href="http://www.oocss.org/">OOCSS</a>. I used it for much of the layout. It makes laying out elements in different browsers very easy. I am using it in the current site as well as the HTML5 experiment. You should use it. It is awesome. <br><br>
<strong>Conclusion</strong><br>
<br>
HTML5 and CSS3 have a lot to offer. And if you have a user base that is fairly modern, you can start using things now. While I may not redo the current dealnews web site using HTML5 and CSS3, our next redesign and any upcoming new designs will definitely include aspects of HTML5 and CSS3 where we can. It can save time and resources when you use these new techniques.<br><br>Here is a link to the <a href="http://brian.moonspot.net/html5exp/html5.html">HTML5 source</a>. I also created a stripped down version of the <a href="http://brian.moonspot.net/html5exp/html4.html">HTML4 in use</a> on the site now.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Mon, 28 Mar 2011 08:00:00 -0500</pubDate>
            <category>css</category>
            <category>html</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/wtf-google-analytics</guid>
            <title>Lies, Damned Lies and Google Analytics</title>
            <link>http://brian.moonspot.net/wtf-google-analytics</link>
            <description><![CDATA[Google Analytics (GA) has changed the world of web analytics. It used to be that you only had applications that analyzed logs from your web server. Those were OK for the first few years. But, with bots (and especially ones that lied about being a bot) and more complex web architectures, those logs became less useful for understanding how your users used your web site.
<br><br>
Once such product was Urchin. Years ago, we were users of Urchin, the product and company that Google purchased to create GA. It was the last really good log analyzer out there. We were kind of excited when Google bought them as we were looking at going to their hosted solution which eventually became GA. At the time however they were young and we decided to go with Omniture, the 800 pound gorilla in the space. However, Omniture prices were such that increased traffic meant increased cost with no additional importance in their numbers and no new features from their product. So, we left them. We turned back to GA. In addition we started using Yahoo's recently acquired product, Yahoo Analytics (formerly IndexTools). They were both free so we figured why not use them both. All this was over 2 years ago.
<br><br>
The one big lacking thing for us with all these tools was being able to tie actual user activity in the analytics to revenue. You see, dealnews does some affiliate based business. This means that we get a percentage of sales after the transactions are all closed. So, we may not see revenue for a user action for days or even weeks. All the analytics packages are made for shopping carts. In a shopping cart, you know at the checkout how much the user spent so you can inject that into the system along with their page view. We don't have that luxury. To try and fill this gap, we started keeping our own javascript based session data in logs for various purposes in addition to the two analytics systems.
<br><br>
Recently we decided to try and use the GA API to get page views, visits and unique visitor data about parts of our site so we could, at least at a high level, tie the numbers all together in one report. This gets me to the meat of this post. What we found was quite disturbing. This is a query for a single day for a particular segment of our site.
We used the <a href="http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html">Data Feed Query Explorer</a> to craft our queries for the data we wanted. This was the result.
<br><br><img  alt="" style="width: 503px;" src="http://moonspot.net/images/img1.png"><br><br>
As you can see, some pages received visitors but no visits. Pages consistently received more visitors than visits which I find quite odd. Sometimes we found that our internal logging would show activity on pages and Google would simply not show any activity for that page for an entire month. Now, I know they have a cutoff. I believe it is still 10,000, the old Urchin number. (C'mon Google, you are Google. You still have this?) They will only store up to 10,000 unique items (page URLs in this case) for a given segment of their reporting data. So, 10k referring domains, 10k pages, etc. etc. Perhaps that is what happened? We dug in and found that to not be the case. And besides, it shows visitors but not visits. What is up with that? Maybe its a date thing. We should look at more days. This is an entire month for the same filters.
<br><br><img  alt="" style="width: 503px;" src="http://moonspot.net/images/img2.png"><br><br>
Whoa, still have visitors and no visits. In addition, there are lots of multiples of 17 there. 17, 34 both appear a lot. We found that littered throughout our results when filtering the page path. This has to be made up data or something. I don't see how it could be based in any reality.
<br><br>
The odd data was not limited to this apparent missing data. There is apparently extra data in there too. In another discussion about the impact of recent social marketing efforts we went to the analytics to see what kind of traffic social networking sites were sending our way. When comparing GA to YA and our internal numbers, we were left baffled. Sorry, no numbers allowed here - super corporate secrets and all that. But, I can tell you that Google Analytics claims that several large, well known referring sites send 5x to 10x the traffic to us that our other tracking reports. I even wrote custom code to try and follow a user through our logs to see if maybe they were attributing referrers to a visitor on a second visit in the day as belonging to the earlier referrer but could never find any pattern that matched their data. There simply is no way this is right.
<br><br>
There is good news. If you stick with the high level numbers like overall page views, visitors, visits and things like new vs. old visitors, the numbers appear to line up well. In all cases, the differences of all 3 of our resources are within acceptable ranges. But, apparently, drilling down too deep in the data with GA will yield some very unsavory answers.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 10 Mar 2011 10:21:36 -0600</pubDate>
            <category>analytics</category>
            <category>javascript</category>
            <category>web</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/git-questions-from-an-svn-user</guid>
            <title>Questions for Git users</title>
            <link>http://brian.moonspot.net/git-questions-from-an-svn-user</link>
            <description><![CDATA[So, we have been using Subversion for a long time. We are very comfortable with it. We know how it works. Even when things go sideways, we have people here that understand it and can set things straight again. But, we do find some things lacking. I had an SVN conflict today where the diff showed the problem to be that I was replacing nothing with something. That was a conflict. Sigh. Also, it is getting slower and slower as time passes. Committing or updating my code base can take long enough that I start checking email and forget I was committing something. So, we are thinking about a switch. I use GitHub for some of my OSS software I have released. I like GitHub a lot. I find the Git command line tool a little confusing (commit -a seems silly for example). But, I figure I can get over that. I am going to end up wrapping it up in our merge and deploy tools anyway. But, I have some questions for people that use Git on a daily basis. I have searched around and there is either more than one answer or no answers to these things.<br><br><strong>How big is your repository?</strong><br><br>We have 1,610 directories and 10,215 files in our code library. How does Git deal with repositories that size?<br><br><strong>What are you using for a Git server?</strong><br><br>From what I can tell, there is no server component to Git. I think I understand that you can use a shared Git use and allow ssh keys to access it that way? Or there are some other 3rd party projects that act as a Git server. We currently use Apache+SVN which lets us A) Use our LDAP server and B) control access to parts of the repository using Apache configuration. It looks like we would lose the LDAP for sure but maybe something like <a href="https://Github.com/sitaramc/Gitolite/">Gitolite</a> would allow us to do some auth/acl stuff. Maybe we could dump our LDAP data on a schedule to something it can read.<br><br><strong>What is your commit, push, deploy procedure?</strong><br><br>This is really aimed at the guys doing continuous deployment in a web application with Git. Our current methodology is that each developer has a branch. They commit to their branch. When a set of commits is ready for release, they push it to trunk. In a staging environment, the changeset in trunk is merged with the production branch. That branch is then rolled to the servers. We like having the 3 layers. It lets us review changes in one place (trunk) for large commits. Meaning there can be 10 commits in a developer's branch, but when all the changes are merged into trunk (using one SVN merge of course) you get one nice neat commit in the trunk branch that can easily be evaluated. It also lets users collaborate easily by committing changes to trunk that others may need. Other users can just merge back from trunk to get the changes. From what I have read or heard people talking about, this seems to fly in the face of how Git works. Or, at least what Git is good at. Also, I think the way Git works, 10 commits in a branch would merge as 10 commits in trunk. So, we would lose the unification of a lot of little changes getting merged into one change. Some of our developers will use their branch to commit things in progress and not at a finished point. So, by the time they are done, we will have 10+ commits for one task. Any input here? <br><br><strong>What are you using for visualization?</strong> <br><br>We use Trac. We love and hate Trac. Its good enough. I know Redmine supports Git natively and I know there is a Trac Hack for making Trac support it. Anything else? Any comments on Redmine?<br><br><strong>Any tips for importing from Subversion?</strong><br><br>I tried importing our Subversion repos into Git using svn2git. It got hung up on some circular branch reference or something. The error message was confusing. So, I guess if we do migrate, we will be starting with little to no history. Perhaps we just import our current production branch and start from there. Any tips?]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 24 Feb 2011 12:36:09 -0600</pubDate>
            <category>git</category>
            <category>svn</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/whats-next-for-message-boards</guid>
            <title>What is next for message board software?</title>
            <link>http://brian.moonspot.net/whats-next-for-message-boards</link>
            <description><![CDATA[When I was hired at <a href="http://dealnews.com/">dealnews.com</a> in 1998, my primary focus was to get our message board (<a href="http://www.phorum.org/">Phorum</a>) up to speed. I had written the first version as a side project for the site. Message boards were a lot simpler back then. <a href="http://www.scriptarchive.com/wwwboard.html">Matt's WWWBoard</a> was the gold standard of the time. And really, the functionality has been only evolutionary since. We added attachments to Phorum in 2003 or something. That was a major new feature. In Phorum 5 we added a module system that was awesome. But, that was just about the admin and not the user. From the user's perspective, message boards have not changed much since 1997. I saw <a href="http://twitter.com/amyhoy/status/34238226575134720">this tweet</a> from Amy Hoy and it got me to thinking about how message boards work. Here is the typical user experience:<br><ol><li>Go to the message board</li><li>See a list of categories</li><li>Drill down to the category they want to read</li><li>Scroll through a list of messages that are in reverse cronological order by original post date or most recent post date</li><li>Click a message and read it.</li><li>Go to #3, repeat</li></ol></li>Every message board software package pretty much works like that and has for over 10 years. And it kind of sucks. What a user would probably rather experience is:<br><ol><li>Go to the message board</li><li>The most interesting things (to this user) are listed right there on the page. No drill down needed.</li><li>Click one and read it.</li><li>Goto #2, repeat.</li></ol></li>Sounds easy? That #2 is easy to type but very hard to accomplish. I think it is conceivably doable if you are running a site that has all the data. <a href="http://stackoverflow.com/">Stackoverflow</a> comes close. When you land on the site, they default the page to the "interesting" posts. However, they are not always interesting to me. They are making general assumptions about their audience. For example, right now, the first one is tagged "delphi". I could care less about that language and any posts about it. Its a good try, but misses by oh so far. This is not a Stackoverflow hate post. They are doing a good job. So, what do I do when I land there? I ignore the front page and click Tags (#2 in the first list), then pick a tag I want to read about (#3 in the first list). Low and behold the page I get is "newest". So, I end up doing exactly what is in the first list I mentioned. They do offer other sort options. But, they chose newest as the default. And from years of watching user behavior, 80% - 90% of people go with the good ol' default. This kind of brings me to another point though about the types of message boards there are.<br><br>Stackoverflow is a classic example of a help message board. People come there and ask a question. Other people come along and answer the question. Then more people come along and vote on whether the answers (and questions) are any good. This is one really nice feature that I think will have to become a core feature in any message board of the future. The signal to noise ratio can get so out of whack, you need human input to help decide what is good and what is noise. I think the core of the application has to rely on that if we are ever going to achieve the desired experience.<br><br>The second type of message board is a conversational system. It is almost like a delayed chat room. People come to a message board and post about their cat or asking who watched a TV show, that kind of thing. This has a completely different dynamic to it than the help message board. You can't really vote if a post is good or bad. The obvious exception being spam would of course want to be recognized and dealt with. <br><br>So, how do you know what content is desirable for the user that is entering the site right now? This concept has already been laid out for us: the social graph. You have to give users a way to associate with other users. If Bob really likes Tom's posts, he is probably more interested to read Tom's post from 30 minutes ago than some new guy that just joined the site and posted 1 minute ago. The challenge here is getting people to interconnect...but not too much. Everyone has that aunt on Facebook that follows you, your roommate and anybody else she can. She would follow your dog if he had a Facebook account. So, those people would still get a crappy experience if the whole system relied on the social graph. The other side is the people that will never "follow", "like" or whatever you call it another person. Their experience would lack as well. One key ingredient here is that you need to own this data. You can't just throw like buttons and Facebook connect on your message board and think you can leverage that data. That data is for Facebook, not you. I think the help message boards could benefit from the social graph as well.<br><br>Another aspect of what is most important to a user is discussions they are involved in. That could mean ones they started, ones they have replied to or simply ones they have read. Which of those aspects are more important than the others? Clearly if you started a discussion and someone has replied, that is going to interest you. If you posted a reply, you may be done with the topic or you may be waiting on a response. It would take some serious natural language algorithms to decide which is the case. For things you have read, I think you have to consider how many times the user has read the discussion. If every time it is updated they read it, they probably will want to read it again the next time it is updated. If they have only read it once, maybe they are not as interested.<br><br>The last aspect of message boards is grouping things. This is the part I actually struggle with the most. The easy first answer is tagging. Don't force the user down a single trail, let them tag posts instead of only posting them in one neat contained area. That gets you half way there. Let's use Stackoverflow (I really do like the site) as an example again. The first thing I do is go to Tags and click on PHP. I like helping people with PHP problems. So,&nbsp; is that really any different from categorization? Sure, there could be someone out there that really likes helping with Javascript. And if the same post was tagged with both tags then their coverage of potential help is larger. But, some of the time those tags are wrong when they tag it with more than one tag. The problem they need help with is either PHP or Javascript, most likely not both. They just don't know what they are doing. For example, there is <a href="http://stackoverflow.com/questions/5100386/personal-finance-app-database-design">this post</a> on Stackoverflow. The user tagged it PHP and database-design. There is no PHP in the question. I am guessing he is using PHP for the app. But, it really never comes up and he is only talking about database design. So, who did the PHP tag help there? I don't think it helped him. And it only wasted my time. Having written all that, a free-for-all approach where there is no filtering sucks too. ARGH! It just all sucks. That brings us back to what Amy said in a way. Perhaps moderated tagging is an answer. I have not seen a way on Stackoverflow to untag a post. That would let people correct others. I am gonna write that down. If you work at Stackoverflow and are reading this, you can use that idea. Just put a comment in the code about how brilliant I am or something that aliens will find one day.<br><br>So, I am done. I know exactly what to do right? I just have to make code that does everything I put in the previous paragraphs. Man I wish it were that easy. When you want to write a distributed application to do it, the task is even more daunting. If I controlled the data and the servers and the code, I could do crazy things that would make great conference talks. But, it kind of falls apart when I want to give this code to a 60 year old retired guy that is starting a hobby site for watching humming birds on a crappy GoDaddy account. Yeah, he is not installing <a href="http://sphinxsearch.com/">Sphinx</a> or <a href="https://github.com/ahiguti/HandlerSocket-Plugin-for-MySQL">HandlerSocket</a> or <a href="http://www.gearman.org/">Gearman</a>. Those are all things I would want to use to solve this problem in a scalable fashion. At that point you have two choices. Aim for the small time or the big time. If you aim for the small time, you may get lots of installs, but, you will be hamstrung. If you aim for the big time, you may be the only guy that ever uses the code. That is a tough decision.<br><br>What have I missed? I know I missed something. Are there other types of message boards? I can definitely see some sub-types. Perhaps a board where ideas instead of help messages are posted. Or maybe the conversations are more show off based as in a user posting pictures or videos for comment. Is there already something out there doing this and I have just missed it? Let me know what I have missed please.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 24 Feb 2011 07:00:00 -0600</pubDate>
            <category>mysql</category>
            <category>phorum</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/geeks-and-public-speaking</guid>
            <title>How does a geek end up doing public speaking?</title>
            <link>http://brian.moonspot.net/geeks-and-public-speaking</link>
            <description><![CDATA[I just finished reading <em><a href="http://www.amazon.com/gp/product/1449301959?ie=UTF8&tag=scottberkunco-20&linkCode=xm2&camp=1789&creativeASIN=1449301959">Confessions of a Public Speaker</a></em> (O'Reilly) by <a href="http://www.scottberkun.com/">Scott Berkun</a>. It is the first book I have read cover to cover in 16 years. I even read the <a href="http://en.wikipedia.org/wiki/Colophon_%28publishing%29">colophon</a> (which I had never seen in a book before). I found the entire book to be very engaging. While reading it, I kept reviewing every mistake I had ever made in every talk I have given. Even if you are not a regular public speaker, there is great stuff in the book that can help you with talking to your coworkers, boss, etc. There is a chapter that is more about teaching than speaking that I found really good. I can really apply a lot of that knowledge to working with my team on new technologies.<br><br>Public speaking was never something I thought I would do when I was younger. I was not on the debate team in high school. I was never the leader of any clubs. The most I ever did was run for class president my senior year. I did not win. The eventual valedictorian who had been the president of our class every year of high school won. That was probably for the best. In fact, I was considered a "rebellious", quiet outsider I later discovered. Ha, a rebel? Me. That seems quite far fetched.<br><br>I first felt like I wanted to share my knowledge with my peers was when I went to <a href="http://www.apachecon.com/">Apachecon</a> in 1999. We were a 4 or 5 person company at the time. But, our CTO had been to regular conferences in his past jobs and found value in the experience. So, he and I took off for Orlando, FL. At the time, Apachecon was really the only well rounded web conference that existed (I find it is not as much this way now). I was excited by the environment I found at the conference. The speakers were not talking heads for faceless corporate giants. They were guys that, like us, were trying to make the web work. Also like us, a lot of them did not have massive investment cash, but were operating on shoestring budgets. Performance and availability mattered. Coming up with new ideas really mattered. We found that we had ideas that others had concurrently. And in some cases, we had ideas that some had not thought about. I would wait another two years to have my turn on stage.<br><br>The web dev/ops team had grown to 5 people. I received an email for the CFP (Call for Proposals) for Apachecon 2001. I thought I had a good idea for a session. The reaction we received from people when we talked about our caching scheme was interesting. Most people had one of two reactions. They either thought the idea was very interesting or they thought we were just dumb. But, the key was that almost everyone had a reaction. So, I thought it would make a good talk. I made every rookie mistake there was. I made my slides the night before the talk. I did not go to the room I was speaking in until it was time to talk. You name it, I did it for the actual presentation. The talk felt like a train wreck. The only good thing about it was, at that time, Apachecon required the presenters to submit a <a href="http://dealnews.com/developers/caching-2001.html">full written version</a> of the session for printing in a book that attendees received. So, we (I was doing the work along with a coworker) had become very familiar with the content. The response we received from the people that attended was incredible. They probably had no idea that the slides were written the night before. But, I have to say, from that point on, I was kind of hooked.<br><br>It would be a few years before I spoke on that type of stage again (<a href="http://www.mysqlconf.com/mysql2008/public/schedule/speaker/66">MySQL Conference, 2008</a>). I seem to have found a home at O'Reilly conferences. Like Apachecon, they embrace people that are doing the work in the field. Sure, you see some talks that feel like sales pitches, but the community quickly exposes those sessions. In the last 5 years, I have spoken at several O'Reilly conferences, another Apachecon and several regional conferences.<br><br>All of this public speaking helped me in a way I never expected. In late 2009, my grandfather passed away. My grandmother, his wife, passed away in 1995. I remember at then having the urge to get and and talk about her. She was a fascinating woman. And there were so many things in my head. But, I lacked the confidence to just get up and say them. So, when my grandfather passed away, I had a completely different mindset. I made it known that I would like to say some things about him. When trying to decide what to say, I found myself using techniques I use for preparing a presentation. I started with several points to make, worked on the right order for the points. Then I went back through and filled in the details of each point. Practicing that "talk" was the hardest practice I have ever had to do for public speaking. No practice or preparation has seemed hard sense. It was an odd clash of my worlds. But, I am so happy I did it. I still have the notes on my iPhone. When I miss him, I get them out and read them. <br><br>Lately, I have branched out from talking to geeks. O'Reilly's <a href="http://ignite.oreilly.com/">Ignite</a> series of events leap out of the geek culture and into your community. We are lucky to have a very good group of people organizing <a href="http://www.ignitebirmingham.com/">Ignite Birmingham</a> in my home town. And while my talks thus far with Ignite Birmingham have had a tech slant, they were not for geeks. I was speaking to a room full of smart, but not nesicarily technical people. It's fun to get outside of my comfort zone. Also, they <a href="http://www.youtube.com/user/ignitebirminghamal">video all the talks</a>. So, I get to see myself and judge my performance. It's great. Speaking to a wider audience is a fun journey that I am finding very exciting and look forward to exploring more. My next challenge for myself is to find a completely non-technical topic for Ignite Birmingham.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 20 Jan 2011 08:00:00 -0600</pubDate>
            <category>personal</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/vlualogger-1-1</guid>
            <title>Release vlualogger 1.1</title>
            <link>http://brian.moonspot.net/vlualogger-1-1</link>
            <description><![CDATA[I have made a small change to <a href="/vlualogger.txt">vlualogger</a> to flush the file handle after every write. I discovered that lua was not flushing the writes when I was tailing a the log file to do some debugging. This fixes that issue.<br><br>Also see my <a href="http://brian.moonspot.net/apache-logs-lua">original post</a> about vlualogger.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Wed, 12 Jan 2011 13:38:28 -0600</pubDate>
            <category>apache</category>
            <category>lua</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/facebook-twitter-mess-up-urls</guid>
            <title>Sharing gotchas on Facebook and Twitter</title>
            <link>http://brian.moonspot.net/facebook-twitter-mess-up-urls</link>
            <description><![CDATA[I have been working on adding some sharing features to <a href="http://dealnews.com/">dealnews.com</a>. Dealing with Facebook and Twitter has been nothing if not frustrating. Neither one seems to understand how to properly deal with escaping a URL. At best they do it one way, but not all ways. At worst, they flat out don't do it right. I thought I would share what we found out so that someone else my be helped by our research.<br><br><strong>Facebook</strong><br><br>Facebook has two main ways to encourage sharing of your site on Facebook. The older way is to "Share" a page. The second, newer, cooler way to promote your page/site on Facebook is with Facebook's Like Button. Both have the same bug. I will focus on Share as it is easier to show examples of sharing. To do this, you make a link and send it to a special landing page on Facebook's site. But, lets say my URL has a comma in it. If it does, Facebook just blows up in horrible fashion. The users of <a href="http://www.phorum.org/">Phorum</a> have run into this problem too. In Phorum, we dealt with register_globals in a unique way long ago. We just don't use traditional query strings on our URLs. Instead of the traditional var1=1&var2=2 format, we decided to use a comma delimited query string. 1,2,3,var4=4 is a valid Phorum URL query string.<br><br>According to <a href="http://tools.ietf.org/html/rfc3986#section-3.4">RFC 3986</a>, a query string is made up of:<br><pre class="newpage">query = *( pchar / "/" / "?" )<br></pre>where pchar is defined as:<br><pre class="newpage">pchar = unreserved / pct-encoded / sub-delims / ":" / "@"<br></pre>and finally, sub-delims is defined as:<br><pre class="newpage">sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / <br> "*" / "+" / "," / ";" / "="</pre>That is RFC talk for "A query string can have an un-encoded comma in it as a delimiter." So, in Phorum we have URLs like&nbsp;<a href="http://www.phorum.org/phorum5/read.php?61,146887,146887"></a><a href="http://www.phorum.org/phorum5/read.php?61,145041,145045">http://www.phorum.org/phorum5/read.php?61,145041,145045</a>. That is the post in Phorum talking about Facebook's problem. It is a valid URL. The commas do not need to be escaped. They are delimiters much like an &amp; would be in a traditional URL. So, what happens when you share this URL on Facebook? Well, a share link would look like <a href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.phorum.org%2Fphorum5%2Fread.php%3F61%2C146887%2C146887">http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.phorum.org%2Fphorum5%2Fread.php%3F61%2C146887%2C146887</a>. If I go to that share page and then look in my Apache logs I see this:<br><pre class="newpage">66.220.149.247 - - [18/Nov/2010:00:47:51 -0600] "GET /phorum5/read.php?61%2C146887%2C146887 HTTP/1.1" 302 26 "-" "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"<br></pre>Facebook sent %2C instead of comma? It decoded the other stuff in the URL. The slashes, the question mark, all of it. So, what is their deal with commas? Well, maybe I can hack Facebook and not send an encoded URL to the share page. Nope, same thing. So, they are proactively encoding commas in URL's query strings. <br><br>This has two effects. The first is that the share app attempts to pull in the title, description, etc. from the page. In this case, we redirect the request as the query string is invalid for a Phorum message page. So, they end up getting the main Phorum page. In the case of dealnews, we usually throw a 400 HTTP error when we get invalid query strings. Neither of these get the user what he wanted. The second problem is that the URL that is clickable when the user has shared the URL is not valid. So, the whole thing was just a huge waste of time.<br><br>I have submitted this to the <a href="http://bugs.developers.facebook.net/show_bug.cgi?id=13655">Facebook Bugzilla</a>. The only work around is to use a URL shortener or don't use commas in your URLs. Just make sure the shortener does not use commas. I guess you could use special URLs for Facebook that used something besides comma that are then redirected to the real URL with commas. I don't know what that character is, I am just guessing.<br><br><strong>Twitter</strong><br><br>Twitter's issues deal with their transition from their old interface to 
their new interface. Twitter is in the process of (or is done with) 
rolling a new UI on their site. The link in the old site to share 
something on Twitter was something like: 
http://twitter.com/home?status=[URL encoded text here]. This worked 
pretty darn well. You could put any valid URL encoded text in there and 
it worked. However, that now redirects you to their new interface's way 
of updating your status and they don't encode things right.<br><br>If I want to tweet "I love to eat pork &amp; beans" I would make the URL <a href="http://twitter.com/home?status=I+love+to+eat+pork+%26+beans">http://twitter.com/home?status=I+love+to+eat+pork+%26+beans</a>. Twitter then takes that, decodes the query string and redirects me to <a href="http://twitter.com/?status=I%20love%20to%20eat%20pork%20&%20beans">http://twitter.com/?status=I%20love%20to%20eat%20pork%20&%20beans</a>. The problem is that they did not re-encode the &. It is in the bare URL. So, when I land on my twitter page, my status box just says "I love to eat pork ". Which while true, is not what I mean to tweet. This bug has been submitted to Twitter, but has yet to be fixed.<br><br>The second problem is with the new site and how they deal with validly encoded spaces. Spaces can be escaped two ways in a URL. The first, older way (which the PHP function <a href="http://php.net/urlencode">urlencode</a> uses) is to encode spaces as a plus (+) sign. This comes from the standard for how forms submit (or used to submit) data. It is understood by all browsers. The second way comes from the later RFC's written about URLs. They state that spaces in a URL should be escape like other characters by replacing a space with %20. The old Twitter UI would accept either one just fine. And, if you send that to the old status update URL it will redirect you (see above) with %20 in the URL instead of +. However, if you send + to the new Twitter UI, as above, you get "I+love+to+eat+pork+&+beans" in your status box. The only solution is to not send + has an encoding for space to Twitter. In PHP you can use the function <a href="http://php.net/rawurlencode">rawurlencode</a> to do this. It conforms to the RFC(s) on URL encoding. Doing so, with thew new linking pattern generates the URL <a href="http://twitter.com/?status=I%20love%20to%20eat%20pork%20%26%20beans">http://twitter.com/?status=I%20love%20to%20eat%20pork%20%26%20beans</a> which works great. This was also reported to Twitter as a bug by our team.<br><br>So, maybe that will help someone out that is having issues with sharing your site on the two largest social networks. Good luck with your social media development.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 18 Nov 2010 07:00:00 -0600</pubDate>
            <category>http</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/monitoring-php-errors</guid>
            <title>Monitoring PHP Errors</title>
            <link>http://brian.moonspot.net/monitoring-php-errors</link>
            <description><![CDATA[PHP errors are just part of the language. Some internal functions throw warnings or notices and seem unavoidable. A good case is parse_url. The point of parse_url is to take apart a URL and tell me the parts. Until recently, the only way to validate a URL was a regex. You can now use filter_var with the FILTER_VALIDATE_URL filter. But, in the past, I would use parse_url to validate the URL. It worked as the function returns false if the value is not a URL. But, if you give parse_url something that is not a URL, it throws a PHP Warning error message. The result is I would use the evil @ to suppress errors from parse_url. Long story short, you get errors on PHP systems. And you don't need to ignore them.<br><br>In the past we just logged them and then had the log emailed daily. On some unregular schedule we would look through them and fix stuff to be more solid. But, when you start having lots of traffic, one notice error on one line could cause 1,000 error messages in a short time. So, we had to find a better way to deal with them.<br><br>Step 1: Managing the aggregation<br><br>The first thing we did was modify our <a href="http://us.php.net/manual/en/function.set-error-handler.php">error handler</a> to log both human readable logs to the defined php error log and to write a serialzed (json_encode actually) version of the error to a second file. This second file makes parsing of the error data super easy. Now we could aggregate the logs on a schedule, parse them and send reports as needed. We have fatal errors monitored more aggressively than non-fatal errors. We also get daily summaries. The one gotcha is that PHP fatal errors do not get sent to the error handler. So, we still have to parse the human readable file for fatal errors. A next step may be to have the logs aggregated to a central server via syslog or something. Not sure where I want to go with that yet.<br><br>Step 2: Monitoring<br><br>Even with the logging, I had no visibility into how often we were logging errors. I mean, I could grep logs, do some scripting to calculate dates, etc. Bleh, lots of work. We recently started using <a href="http://circonus.com/">Circonus</a> for all sorts of metric tracking. So, why not PHP errors? Circonus has a data format that allows us to send any random metrics we want to track to them. They will then graph them for us. So, in my error handler, I just increment a counter in memached every time I log an error. When Circonus polls me for data, I just grab that value out of memcached and give it to them. I can then have really cool graphs that show me my error rate. In addition I can set alerts up. If we start seeing more than 1 error per second, we get an email. If we start seeing more than 5 per second, we get paged. You get the idea.<br><br>The Twitterverse:<br><br>I polled my friends on Twitter and two different services were mentioned. I don't know that I would actually send my errors to a service, but it sounds like an interesting idea. One was <a href="http://hoptoadapp.com/">HopToad</a>. It appears to be specifically for application error handling. The other was <a href="http://www.loggly.com/">loggly</a> which appears to be a more generic log service. Both very interesing concepts. The control freak in me would have issues with it. But, that is a personal problem.<br><br>Most others either manually reviewed things or had some similar notification system in place. Anyone else have a brilliant solution to monitoring PHP errors? Or any application level errors for that matter?<br><br>P.S. For what it is worth, our PHP error rate is about .004 per second. This includes some notices. Way too high for me. I want to approach absolute zero. Lets see if all these new tools can help us get there.<br><div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div>]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Mon, 08 Nov 2010 08:00:00 -0600</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/nusphere-spam</guid>
            <title>Boycott NuSphere. They are spammy spammers</title>
            <link>http://brian.moonspot.net/nusphere-spam</link>
            <description><![CDATA[It took a lot for me to finally write this post. I <a href="http://twitter.com/#%21/brianlmoon/status/27729973155">tweeted about it</a> a while back. It seems NuSphere needs more business. They have resorted to spamming people to promote their PhpED product. I have gotten emails to email addresses that:<br><ol><li>I know are not on any mailing list</li><li>Are on web pages as plain mailto: anchor tags for good reasons.</li></ol></li>In one case, it was the security@phorum.org address we have on the site to make it easy for people to report any security related issues. We get all kind of spam because of this, but it is worth it to have an easy access address for security issues.<br><br>In the other case, the email addresses used were on the dealnews.com jobs page. It was the addresses that are used to accept resumes.<br><br>Now, today, I started getting them to my personal inboxes.<br><br><img  alt="" style="width: 620px; height: 192px;" src="http://moonspot.net/images/nusphere.png"><br><br>Apparently, they sent it out the first time with a misspelling, so they had to send it out again!?!?<br><br>Now, the NuSphere people <a href="http://twitter.com/#%21/PHP_IDE/status/27995673318">posted a tweet</a> that claims the emails are not coming from them. That it's an independent marketer that "<em>have permission to sell our products</em>". First, the links in the email to go the NuSphere site, not a 3rd party. I would think an independent would want to take me to their site. Second, if that is the case, revoke the permission you have given them to sell your products. Don't use a marketing/sales agreement as a shield to allow people in the PHP Community to be spammed in your name.<br><br>PHP Community, please do no support NuSphere. They are spammers, directly or indirectly. If they do this to promote their product, how will they find a way to hose their user base later on?]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Thu, 28 Oct 2010 00:41:12 -0500</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/php-5-3-mysqlnd</guid>
            <title>PHP 5.3 and mysqlnd - Unexpected results</title>
            <link>http://brian.moonspot.net/php-5-3-mysqlnd</link>
            <description><![CDATA[I have started seriously using PHP 5.3 recently due to it finally making it into <a>Portage</a>. (Gentoo really isn't full of bleeding edge packages people.) I have used mysqlnd a little here and there in the past, but until it was really coming to my servers I did not put too much time into it.<br><br><strong>What is mysqlnd?</strong><br><br>mysqlnd is short for MySQL Native Driver. In short, it is a driver for MySQL for PHP that uses internal functions of the PHP engine rather than using the externally linked libmysqlclient that has been used in the past. There are two reasons for this. The first reason is licensing. MySQL is a GPL project. The GPL and the PHP License don't play well together. The second is better memory management and hopefully more performance. Being a performance junky, this is what peaked my interests. Enabling mysqlnd means it is used by the older MySQL extension, the newer MySQLi extension and the MySQL PDO driver.<br><br><strong>New Key Feature - fetch_all</strong><br><br>One new feature of mysqlnd was the fetch_all method on MySQLi Result objects. At both <a href="http://dealnews.com/">dealnews.com</a> and in <a href="http://www.phorum.org/">Phorum</a> I have written a function to simply run a query and fetch all the results into an array and return it. It is a common operation when writing API or ORM layers. mysqlnd introduces a native fetch_all method that does this all in the extension. No PHP code needed. PDO already offers a fetchAll method, but PDO comes with a little more overhead than the native extensions and I have been using mysql functions for 14 years. I am very happy using them.<br><br><strong>Store Result vs. Use Result</strong><br><br>I have spoken in the past (see my slides and interview: <a>MySQL Tips and Tricks</a>) about using mysql_unbuffered_query or using mysqli_query with the MYSQLI_USE_RESULT flag. Without going into a whole post about that topic, it basically allows you to stream the results from MySQL back into your PHP code rather than having them buffered in memory. In the case of libmysqlclient, they could be buffered twice. So, my natural thought was that using MYSQLI_USE_RESULT with fetch_all would yield the most awesome performance ever. The data would not be buffered and it would get put into a PHP array in C instead of native code. The code I had hoped to use would look like:<pre>$res = $db-&gt;query($sql, MYSQLI_USE_RESULT);<br>$rows = $res-&gt;fetch_all(MYSQLI_ASSOC);<br></pre>
But, I quickly found out that this does not work. For some reason, this is not supported. fetch_all only works with the default which is MYSQLI_STORE_RESULT. I filed a bug which was marked bogus. Which I put back to new because I really don't see a reason this should not work other than a complete oversight by the mysqlnd developers. So, I started doing some tests in hopes I could show the developers how much faster using MYSQLI_USE_RESULT could be. What happened next was not expected. I ended up benchmarking several different options for fetching all the rows of a result into an array.<br><br><strong>Test Data</strong><br><br>I tested using PHP 5.3.3 and MySQL 5.1.44 using InnoDB tables. For test data I made a table that has one varchar(255) column. I filled that table with 30k rows of random lengths between 10 and 255 characters. I then selected all rows and fetched them using 4 different methods.<span class="methodname"></span><span style="font-weight: bold;"></span><br><ol><li><a href="http://us.php.net/manual/en/mysqli-result.fetch-all.php">mysqli_result::fetch_all*</a></li><li><a href="http://us.php.net/manual/en/pdostatement.fetchall.php">PDOStatement::fetchAll</a></li><li><a href="http://us.php.net/manual/en/mysqli.query.php">mysqli_query with MYSQLI_STORE_RESULT followed by a loop</a></li><li><a href="http://us.php.net/manual/en/mysqli.query.php">mysqli_query with MYSQLI_USE_RESULT followed by a loop</a></li></ol></li>In addition, I ran this test with mysqlnd enabled and disabled. For mysqli_result::fetch_all, only mysqlnd was tested as it is only available with mysqlnd. I ran each test 6 times and threw out the worst and best result for each test. FWIW, the best and worst did not show any major deviation for any of the tests. For measuring memory usage, I read the VmRSS value from Linux's /proc data. memory_get_usage() does not show the hidden memory used by libmysqlclient and does not seem to show all the memory used by mysqlnd either.<br><br><img  alt="" style="width: 574px;" src="http://content.screencast.com/users/brianlmoon/folders/Jing/media/18ecdea6-1a2c-4b9b-b267-b7676effdcb1/00000117.png"><br><br>So, that is what I found. The memory usage graphs are all what I thought they would be. PDO has more overhead by its nature. Storing the result always uses more memory than using it. mysqli_result::fetch_all uses less memory than the loop, but more than directly using the results. <br><br>There are some very surprising things in the timing graphs however. First, the tried and true method of using the result followed by a loop is clearly still the right choice in libmysqlclient. However, it is a horrible choice for mysqlnd. I don't really see why this is so. It is nearly twice as slow. There is something really, really wrong with MYSQLI_USE_RESULT in mysqlnd. There is no reason it should ever be slower than storing the result and then reading it again. This is also evidenced in the poor performance of PDO (since even PDO uses mysqlnd when enabled). PDO uses an unbuffered query for its fetchAll method and it too got slower. It is noticably slower than libmysqlclient. The good news I guess is that if you are using mysqlnd, the fetch_all method is the best option for getting all the data back. <br><br><strong>Next Steps</strong><br><br>My next steps from here will be to find some real workloads that I can test this on. Phorum has several places where I can apply real world pages loads to these different methods and see how they perform. Perhaps the test data is too small. Perhaps the number of columns would have a different effect. I am not sure.<br><br>If you are reading this and have worked on or looked at the mysqlnd code and can explain any of it, please feel free to comment.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Tue, 03 Aug 2010 08:00:00 -0500</pubDate>
            <category>mysql</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/engineers-work-in-their-sleep</guid>
            <title>Engineers Work In Their Sleep</title>
            <link>http://brian.moonspot.net/engineers-work-in-their-sleep</link>
            <description><![CDATA[My grandmother worked at the <a href="http://www.nasa.gov/centers/marshall/home/index.html">Marshall Space Flight Center</a>. She worked with a lot of engineers. I have always remembered when she told my cousin and I that we should be engineers. Her reasoning was that if you saw a janitor sitting in a chair with his arms crossed and his eyes closed, you pretty much knew he was not working. But, if you see an engineer in the same position, you can not prove he is not working. Now, was she saying she wanted us to sleep on the job? No, of course not. The message was to have a job where you could use your mind. Although I think watching our grandfather work hard every day as a construction foreman may have shaped her opinion. You know what is funny about that? He was the healthiest man I have ever known. Maybe I don't need to be sitting behind a desk with my arms crossed and eyes closed?<br><br>For what it is worth, I don't believe that all jobs that use your mind are desk jobs. Some of the smartest people I know have jobs in fields that would be 
considered "manual" labor. I believe that smart people will always rise to the top no matter what your profession.<div firebugversion="1.5.4" style="display: none;" id="_firebugConsole"></div>]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Wed, 07 Jul 2010 10:42:07 -0500</pubDate>
            <category>personal</category>
            <category>programming</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/velocity-2010-in-review</guid>
            <title>Velocity 2010 In Review</title>
            <link>http://brian.moonspot.net/velocity-2010-in-review</link>
            <description><![CDATA[I just got back from <a href="http://en.oreilly.com/velocity2010">Velocity</a> for the third straight year. I have been to all three of them which is kind of a neat little club to be in. The first one only had maybe 300 people. This year there were over 1,000 attendees. Registration was shut down by the fire code for the rooms we were using. Most sessions had standing room only. It was awesome.<br><br>The people that talk at Velocity are really smart. I am always humbled by the likes of <a href="http://www.kitchensoap.com/">John Allspaw</a>. He and I see eye to eye on a lot, but he is so much better at explaining to people and showing them how to make the ideas work. I wish I had his charisma when at the podium. I was lucky enough to write a chapter in a book for John this year. He and Velocity co-chairperso<span>n Jesse Robbins organized and authored a book titled <a href="http://www.amazon.com/Web-Operations-Keeping-Data-Time/dp/1449377440/ref=sr_1_1?ie=UTF8&s=books&qid=1277623606&sr=8-1">Web Operations</a> that debuted at the conference. I basically just told and expanded on my <a href="http://brian.moonspot.net/2006/12/22/is-yahooed-a-word/">Yahoo story</a>. John loves that story for some reason. I was happy to be a part of it. So many smart people in that book.<br><br>The <a href="http://ie.microsoft.com/testdrive/">IE9 technology preview</a> dropped while we were there. HTML 5, CSS 3 and more in there. One feature where Microsoft is actually ahead of the curve is in a new DOM level measurement feature. Basically they expose statistics via the DOM about the time it takes to do different things in the page. The other browser vendors in attendance (Google and Mozilla) vowed to support the same data. Another big advancement of IE9 is the heavy use of the GPU for rendering the pages. They have a real advantage here. They are the only browser vendor that is now locked to one operating system. IE9 will require Vista or higher. They can really max out the system for faster rendering.<br><br>As usual some of the best content was in the hall ways and bar. We hung out with <a href="http://omniti.com/is/theo-schlossnagle">Theo Schlossnagle</a> from OmniTI and talked about <a href="https://labs.omniti.com/trac/reconnoiter">Reconnoiter</a>. It is a kind of Cacti/Ganglia/Nagios all in one. I got to see the Six Apart guys again this year. That is becoming an annual thing. I shared our new Gearman assisted proxy with them. They do some similar stuff for TypePad. More on that proxy later this year. I met a guy from <a href="http://www.soasta.com/product/">CloudTest</a>. It sounds like a really good use of on-demand cloud resources. I am gonna talk with them about some possible testing.<br><br><a href="http://membase.org/">Membase</a> also dropped while we were there. Most of the persistent key/value stores I have used have disappointed me or just been way too complex for our needs. We don't want a memcached replacement. It does its job damn well. I just need a place to store adhoc data for various applications. Membase is promising because the guys that wrote it are core memcached contributors. There is a company behind it, so it is not as inviting as Drizzle. But, the code is on GitHub so it is more open than say MySQL. Time will tell.<br><br>If you have not been to Velocity I encourage you to go next year. It is right for all types of people in the web business. Developers can learn about performance in new ways that will change they way they write code. Operations can learn techniques to make their work day much less painful. Everyone will learn how to empower their business to achieve the goals of the business. <br></span>]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Mon, 28 Jun 2010 08:00:00 -0500</pubDate>
            <category>devops</category>
            <category>scalability</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/php-memcached-issues</guid>
            <title>PHP and Memcached: The state of things</title>
            <link>http://brian.moonspot.net/php-memcached-issues</link>
            <description><![CDATA[Memcached is the de facto standard for caching in dynamic web sites. PHP is the one of the most widely used languages on the web. So, naturally there is lots of interest in using the two together. There are two choices for using memcached with PHP: <a href="http://pecl.php.net/package/memcache">PECL/memcache</a> and <a href="http://pecl.php.net/package/memcached">PECL/memcached</a>.
 Great names huh? But as of this writing there are issues with the two most popular Memcached libraries for PHP. This is a summary of those issues that I hope will help people being hurt by them and may bring about some change.<br><br><strong>PECL/memcache</strong><br><br>This is the older of the two and was the first C based extension for using memcached with PHP. Before this all the options were native PHP code. While they worked, they were slower of course. C &gt; PHP. That is just fact. However, there has not been much active development on this code in some time. Yes, they have fixed bugs, but support for new features in the memcached server have not been added to this extension. Newer version of the server suppot a more efficient binary protocol and many new features. In addition, there are some parts of the extension that simply don't work anymore. <br><br>The most glaring one is the <a href="http://us3.php.net/manual/en/memcache.delete.php">delete()</a> function. It takes a second parameter that is documented as: "the item will expire after
 <em><tt class="parameter">timeout</tt></em> seconds". In fact that was never a feature of memcached. It was completely misunderstood by the original extension authors. When that parameter was supported, it locked the key for <em><tt class="parameter">timeout</tt></em> seconds and would not allow a new add operation on that key. Second, this feature was completely removed in memcached 1.4.0. So, if you send a timeout to the delete function, you simply get a failure. This is creating a huge support issue in the memcached community (not the PHP/PECL community) with people not being able to delete keys because of bad documentation and unsupported behavior. I sent a documentation patch for the this function to the PHP Docs list. I then modified it based on feedback. But since I have heard nothing about it getting merged. I have a PHP svn account, but even if I do have karma on the docs repository, I don't want to hijack them without the support of the people that work on the docs all the time. If you are reading this and can change the docs, please make the documentation for that function say "DON'T USE THIS PARAMETER, IT HAS BEEN DEPRECATED IN THE MEMCACHED SERVER!" or something.<br><br>Not too long ago the extension was <a href="http://marc.info/?l=pecl-dev&m=126926486801449&w=2">officially abandoned</a> by its original maintainers. Some people stepped up and claimed they wanted to see it continue. But, since that time, there have been no releases. There are bugs being closed though so maybe there is good things coming.<br><br>A very problematic issue with this extension is with the 3.0 beta release. It needs to just die. It has huge bugs that, IMO, were introduced by the previous maintainers in an effort to bring it up to speed, but never saw them through to make sure the new code worked. In their defense, it is marked as beta on PECL. But, thanks to Google, people don't see the word beta anymore. There are lots of people using this version and when they get bad results they blame the whole memcached world. Really, the new maintainers would do the world a favor if they just removed the 3.x releases from the PECL site.<br><br><strong>PECL/memcached</strong><br><br>This extension was started by Andrei Zmievski while working at Digg.com as an open source developer. It uses <a href="http://libmemcached.org/">libmemcached</a>, a C++ memcached library that does all the memcached work. This made it quite easy to support the new features in the memcached daemon as it as it was being developed at the same time as the new server. However, it has not had a stable release on PECL in nearly a year except for release to make it compatible with new versions of libmemcached. No bug fixes and no new features. There are currently 28 open bugs on PECL for this extension. Not all of which are bugs. Some are feature requests. The ironic thing is that the <a href="http://github.com/andreiz/php-memcached">GitHub repository</a> for this extension has seen a lot of development. But, none of these bug fixes have made it into the official PECL channel. And some of these bugs are major and others are just huge WTF for a developer.<br><br>The most major bug is one that I found. If you use persistent connections with this extension, it basically leaks those connections, not reusing an existing connection but also not closing the ones already made. This uses up the memory in your processes until they crash and it creates an exponential number of connections to your memcached server until it has no more connections available. Andrei does report in the bug that it is fixed in hist GitHub. But, for now, you can't use persistent connections.<br><br>The big WTF for a developer is that some functions don't take a numeric key and use it properly.<pre>&lt;?php<br><br>$mc = new Memcached();<br><br>$mc-&gt;addServer("localhost", 11211);<br><br>$mc-&gt;set(123, "yes!");<br><br>var_dump($mc-&gt;getMulti(array(123)));<br><br>?&gt;</pre>The above code should generate:<pre>array(1) {<br>&nbsp; [123]=&gt;<br>&nbsp; string(4) "yes!"<br>}</pre>But, in reality, it generates:<pre>bool(false)</pre>The set succeeds, but the getMulti fails. Again, this is being fixed in GitHub, but is not available for release on PECL.<br><br><strong>Compatibility</strong><br><br>One big issue with these two extensions is that they are not drop in replacements for each other. If you want to move from one to the other, you have to take into consideration some time to convert your code. For instance, the older extension's set() function takes flags as the third parameter. The newer extension does not take a flags parameter at all. The older uses get() with an array to do a multi-get and the newer extension has a separate method for that called getMulti(). There are others as well.<br><br><strong>Summary</strong><br><br>So, what should you do as a PHP developer? If you are deploying memcached today, I would use the 2.2.x branch of PECL/memcache. It is the most stable. Just avoid the delete bug. It is not as fast and does not have the features. But, it is very reliable for set, get, add.... the basics of memcached. For the long term, it is a bit unclear. PECL/memcached looks to fix a lot of things in 2.0. But, I have not used it yet. In addition the long term growth of the project is a bit in question. Will there be a 2.1, 2.2, etc? I hope so. The other unknown is if the those people fixing the PECL/memcache bugs will keep it up and release a good stable product that supports new features of the server. Again, I hope so. The best scenario would be to have a choice between two fully compatible and feature rich extensions. Keep your fingers crossed.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Wed, 23 Jun 2010 11:48:31 -0500</pubDate>
            <category>memcached</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/php-generated-code</guid>
            <title>PHP generated code tricks</title>
            <link>http://brian.moonspot.net/php-generated-code</link>
            <description><![CDATA[<span style="font-family: Verdana,Arial,Helvetica,sans-serif;"></span>Something that is great about PHP is that you can write code that generates more PHP code to be used later. Now, I am not saying this a best practice. I am sure it violates some rule in some book somewhere. But, sometimes you need to be a rule breaker.<br>
<br>
A simple example is taking a database of configuration information and dumping it to an array. We do this for each publication we operate. We have a publication table. It contains the name, base URL and other stuff that is specific to that publication. But, why query the database for something that only changes once in a blue moon? We could cache it, but that would still require an on demand database hit. The easy solution is to just dump the data to a PHP array and put it on disk.<br>

<pre>&lt;?php<br><br>$sql = "select * from publications";<br><br>$res = $mysqli-&gt;query($sql);<br><br>while($row = $res-&gt;fetch_assoc()){<br><br>&nbsp;&nbsp;&nbsp; $pubs[$row["publication_id"]] = $row;<br><br>}<br><br>$pubs_ser = str_replace("'", "\\'", serialize($pubs));<br><br>$php_code = "&lt;?php global \$PUBLICATIONS; \$PUBLICATIONS = unserialize('$pubs_ser'); ?&gt;";<br><br>file_put_contents("/some/path/publications.php", $php_code);<br><br>?&gt;<br></pre>

Now you can include the publications.php file and have a global variable named $PUBLICATIONS that holds the publication settings. But, how do we load a single publication without knowing numeric ids? Well, you could make some constants.

<pre>&lt;?php<br><br>$sql = "select * from publications";<br><br>$res = $mysqli-&gt;query($sql);<br><br>while($row = $res-&gt;fetch_assoc()){<br><br>&nbsp;&nbsp;&nbsp; $pubs[$row["publication_id"]] = $row;<br><br>&nbsp;&nbsp;&nbsp; $constants[$row["publication_id"]] = strtoupper($row["name"]);<br><br>}<br><br>$pubs_ser = str_replace("'", "\\'", serialize($pubs));<br><br>$php_code = "&lt;?php\n";<br><br>$php_code.= "global \$PUBLICATIONS;\n";<br><br>$php_code.= "\$PUBLICATIONS = unserialize('$pubs_ser');\n";<br><br>foreach($constants as $id=&gt;$const){<br><br>&nbsp;&nbsp;&nbsp; $php_code.= "define('$const', $id);\n";<br><br>}<br><br>$php_code.= "?&gt;";<br><br>file_put_contents("/some/path/publications.php", $php_code);<br><br>?&gt;<br><br></pre>

So, now, we have constants. We can do stuff like:
<pre>&lt;?php<br><br>//load a publication<br><br>require_once "publications.php";<br><br>echo $PUBLICATIONS[DEALNEWS]["name"];<br><br>?&gt;</pre>But, how about autoloading? It would be nice if I could just autoload the constants.
<pre>&lt;?php<br><br>$sql = "select * from publications";<br><br>$res = $mysqli-&gt;query($sql);<br><br>while($row = $res-&gt;fetch_assoc()){<br><br>&nbsp;&nbsp;&nbsp; $pubs[$row["publication_id"]] = $row;<br><br>&nbsp;&nbsp;&nbsp; $constants[$row["publication_id"]] = strtoupper($row["name"]);<br><br>}<br><br>$pubs_ser = str_replace("'", "\\'", serialize($pubs));<br><br>$php_code = "&lt;?php\n";<br><br>$php_code.= "class PUB_DATA {\n";<br><br>foreach($constants as $id=&gt;$const){<br><br>&nbsp;&nbsp;&nbsp; $php_code.= " const $const = $id;\n";<br><br>}<br><br>$php_code.= "&nbsp;&nbsp;&nbsp; protected \$pubs_ser = '$pubs_ser';\n";<br><br>$php_code.= "}";<br><br>$php_code.= "?&gt;";<br><br>file_put_contents("/some/path/pub_data.php", $php_code);<br><br>?&gt;</pre>
Then we create a class in our autoloading directory that extends that object.<br><pre>&lt;?php<br><br>require_once "pub_data.php";<br><br>class Publication extends PUB_DATA {<br><br>&nbsp;&nbsp;&nbsp; private $pub;<br><br>&nbsp;&nbsp;&nbsp; public function __construct($pub_id) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $pubs = unserialize($this-&gt;pubs_ser);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;pub = $pubs[$pub_id];<br><br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; public function __get($var) {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(isset($this-&gt;pub[$var])){<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $this-&gt;pub[$var];<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Exception<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; }<br><br>}<br><br>?&gt;</pre>
Great, now we can do things like:
<pre>$pub = new Publication(Publication::DEALNEWS);<br><br>echo $pub-&gt;name;<br></pre>
The only problem that remains is dealing with getting the generated code to all your servers. We use rsync. It works quite well. You may have a different solution for your team. Back when we ran our own in house ad server we did all the ad work this way. None of the ad calls ever hit the database to get ads. We stored stats on disk in logs and processed them on a schedule. It was a very solid solution.<br>
<br>
One more benefit of using generated files on disk is that they can be cached by APC or XCache. This means you don't have to actually hit disk for them all the time.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Fri, 18 Jun 2010 13:56:07 -0500</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/understanding-mysql-indexes</guid>
            <title>Want to understand MySQL indexes?</title>
            <link>http://brian.moonspot.net/understanding-mysql-indexes</link>
            <description><![CDATA[I have introduced some new people to MySQL recently and had to back track the years to figure out how I learned what I learned about MySQL indexes.&nbsp; A quick way to get up to speed about MySQL indexes is these three podcasts by <a href="http://www.sheeri.com/">Sheeri Cabral</a>.<br><ol><li><a href="http://www.technocation.org/content/oursql-episode-13%3A-nitty-gritty-indexes">OurSQL Episode 13: The Nitty Gritty of Indexes</a></li><li><a href="http://www.technocation.org/content/oursql-episode-17%3A-hashing-it-out-0">OurSQL Episode 17: Hashing it out</a></li><li><a href="http://www.technocation.org/content/oursql-episode-18%3A-de-myth-tifying-indexes-0">OurSQL Episode 18: De-myth-tifying Indexes</a></li></ol></li>Those three episodes do a good job of explaining how indexes work so that you have a better understanding of how MySQL indexes find your data.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Tue, 15 Jun 2010 17:14:40 -0500</pubDate>
            <category>mysql</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/mysql-conference-review</guid>
            <title>MySQL Conference Review</title>
            <link>http://brian.moonspot.net/mysql-conference-review</link>
            <description><![CDATA[I am back home from a good week at the 2010 O'Reilly MySQL Conference &amp; Expo. I had a great time and got to see some old friends I had not seen in a while.<br><br>Oracle gave the opening keynote and it went pretty much like I thought it would. Oracle said they will keep MySQL alive. They talked about the new 5.5 release. It was pretty much the same keynote Sun gave last year. Time will tell what Oracle does with MySQL.<br><br>The expo hall was sparse. Really sparse. There were a fraction of the booths compared to the past. I don't know why the vendors did not come. Maybe because they don't want to compete with Oracle/Sun? In the past you would see HP or Intel have a booth at the conference. But, with Oracle/Sun owning MySQL, why even try. Or maybe they are not allowed? I don't know. It was just sad.<br><br>I did stop by the <a href="http://www.maatkit.org/">Maatkit</a> booth and was embarrassed to tell <a href="http://www.xaprb.com/">Baron</a> (its creator) I was not already using it. I had heard people talk about it in the past, but never stopped to see what it does. It would have only saved me hours and hours of work over the last few years. Needless to say it is now being installed on our servers. If you use MySQL, just go install Maatkit now and start using it. Don't be like me. Don't wait for years, writing the same code over and over to do simple maintenance tasks.<br><br><a href="http://gearman.org/">Gearman</a> had a good deal of coverage at the conference. There were three talks and a <a href="http://en.wikipedia.org/wiki/Birds_of_a_Feather_%28computing%29">BoF</a>. All were well attended. Some people seemed to have an AHA! moment where they saw how Gearman could help their architecture. I also got to sit down with the PECL/gearman maintainers and discuss the recent bug I found that is keeping me from using it.<br><br>I spoke about <a href="http://memcached.org/">Memcached</a> as did others. Again, there was a BoF. It was well attended and people had good questions about it. There seemed to be some FUD going around that memcached is somehow inefficient or not keeping up with technology. However, I have yet to see numbers or anything that proves any of this. They are just wild claims by people that have something to sell. Everyone wants to be the caching company since there is no "Memcached, Inc.". There is no company in charge. That is a good thing, IMO.<br><br>That brings me to my favorite topic for the conference, Drizzle. I <a href="http://brian.moonspot.net/2008/07/24/156/">wrote about Drizzle</a> here on this blog when it was first announced. At the time MySQL looked like it was moving forward at a good pace. So, I had said that it would only replace MySQL in one part of our stack. However, after what, in my opinion, has been a lack of real change in MySQL, I think I may have changed my mind. Brian Aker echoed this sentiment in <a href="http://www.slideshare.net/brianaker/drizzle-keynote-at-the-mysql-users-conference">his keynote address about Drizzle</a>. He talked about how MySQL AB and later Sun had stopped focusing on the things that made MySQL popular and started trying to be a cheap version of Oracle. That is my interpretation of what he said, not his words. <br><br>Why is Drizzle different? Like Memcached and Gearman, there is no "Drizzle, Inc.". It is an Open Source project that is supported by the community. It is being supported by companies like <a href="http://www.rackspacecloud.com/blog/2010/03/13/rackspace-and-drizzle-its-time-to-rethink-everything/">Rackspace who hired five developers</a> to work on it. The code is kept on <a href="https://launchpad.net/drizzle">Launchpad</a> and is completely open. Anyone can create a branch and work on the code. If your patches are good, they will be merged into the main branch. But, you can keep your own branch going if you want to. Unlike the other forks, Drizzle has started over in both the code and the community. I personally see it as the only way forward. It is not ready today, but my money is on Drizzle five or ten years from now.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Sat, 17 Apr 2010 10:54:52 -0500</pubDate>
            <category>drizzle</category>
            <category>gearman</category>
            <category>memcached</category>
            <category>mysql</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/devops-dealnews</guid>
            <title>DevOps at dealnews.com</title>
            <link>http://brian.moonspot.net/devops-dealnews</link>
            <description><![CDATA[I was telling someone how we roll changes to production at dealnews and they seemed really amazed by it. I have never really thought it was that impressive. It just made sense. It has kind of happened organically here over the years. Anyhow, I thought I would share.<br><br><strong>Version Control</strong><br><br>So, to start with, everything is in SVN. PHP code, Apache configs, DNS and even the scripts we use to deploy code. That is huge. We even have a misc directory in SVN where we put any useful scripts we 
use on our laptops for managing our code base. Everyone can share that 
way. Everyone can see what changed when. We can roll things back, branch if we need to, etc. I don't know how anyone lives with out. We did way back when. It was bad. People were stepping on each other. It was a mess. We quickly decided it did not work. <br><br>For our PHP code, we have trunk and a production branch. There are also a couple of developers (me) that like to have their own branch because they break things for weeks at a time. But, everything goes into trunk from my branch before going into production. We have a PHP script that can merge from a developer branch into trunk with conflict resolution assistance built in. It is also capable of merging changes from trunk back into a branch. Once it is in trunk we use our staging environment to put it into production.<br><br><strong>Staging/Testing<br></strong><br>Everything has a staging point. For our PHP code, it is a set of test staging servers in our home office that have a checkout of the production branch. To roll code, the developer working on the project logs in via ssh to a staging server as a restricted user and uses a tool we created that is similar to the Python based <a href="http://www.orcaware.com/svn/wiki/Svnmerge.py">svnmerge.py</a>. Ours is written in PHP and tailored for our directory structure and roll out procedures. It also runs php -l on all .php and .html files as a last check for any errors. Once the merge is clean, the developer(s) use the staging servers just as they would our public web site. The database on the staging server is updated nightly from production. It is as close to a production view of our site as you can get without being on production. Assuming the application performs as expected, the developer uses the merge tool to commit the changes to the production branch. They then use the production staging servers to deploy.<br><br><strong>Rolling to Production </strong><br><br>For deploying code and hands on configuration changes into our production systems, we have a staging server in our primary data center. The developer (that is key IMO) logs in to the production staging servers, as a restricted user, and uses our Makefile to update the checkout and rsync the changes to the servers. Each different configuration environment has an accompanying nodes file that lists the servers that are to receive code from the checkout. This ensures that code is rolled to servers in the correct order. If an application server gets new markup before the supporting CSS or images are loaded onto the CDN source servers, you can get an ugly page. The Makefile is also capable of copying files to a single node. We will often do this for big changes. We can remove a node from service, check code out to it, and via VPN access that server directly to review how the changes worked. <br><br>For some services (cron, syslog, ssh, snmp and ntp) we use Puppet to manage configuration and to ensure the packages are installed. Puppet and Gentoo get along great. If someone mistakenly uninstalls cron, Puppet will put it back for us. (I don't know how that could happen, but ya never know). We hope to deploy more and more Puppet as we get comfortable with it. <br><br><strong>Keeping Everyone in the Loop</strong><br><br>Having everyone know what is going on is important. To do that, we start with Trac for ticketing. Secondly, we use OpenFire XMPP server throughout the company. The devops team has a channel that everyone is in all day. When someone rolls code to production, the scripts mentioned above that sync code out to the servers sends a message via an XMPP bot that we wrote using Ruby (Ruby has the best multi-user chat libraries for XMPP). It interfaces with Trac via HTTP and tells everyone what changesets were just rolled and who committed them. So, in 5 minutes if something breaks, we can go back and look at what just rolled.<br><br>In addition to bots telling us things, there is a cultural requirement. Often before a big roll out, we will discuss it in chat. That is the part than can not be scripted or programmed. You have to get your developers and operations talking to each other about things.<br><br><strong>Final Thoughts</strong><br><br>There are some subtle concepts in this post that may not be clear. One is that the code that is written on a development server is the exact same code that is <a href="http://brian.moonspot.net/develop-for-production">used on a production server</a>. It is not massaged in any way. Things like database server names, passwords, etc. are all kept in <a href="http://brian.moonspot.net/using-ini-files-for-php-application-settings">configuration files on each node</a>. They are tailored for the data center that server lives in. Another I want to point out again is that the person that wrote the code is responsible all the way through to production. While at first this may make some developers nervous, it eventually gives them a sense of ownership. Of course, we don't hire someone off the street and give them that access.&nbsp; But it is expected that all developers will have that responsibility eventually.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Mon, 05 Apr 2010 08:00:00 -0500</pubDate>
            <category>devops</category>
            <category>php</category>
            <category>svn</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/logging-with-mysql</guid>
            <title>Logging with MySQL</title>
            <link>http://brian.moonspot.net/logging-with-mysql</link>
            <description><![CDATA[I was reading a post by <span class="post-author vcard"><span class="fn">Dathan Vance Pattishall titled "</span></span><a href="http://mysqldba.blogspot.com/2010/03/cassandra-is-my-nosql-solution-but.html">Cassandra is my NoSQL solution but..</a>". In the post, Dathan explains that he uses Cassandra to store clicks because it can write a lot faster than MySQL. However, he runs into problems with the read speed when he needs to get a range of data back from Cassandra. This is the number one problem I have with NoSQL solutions.<br><br>SQL is really good at retrieving a set of data based on a key or range of keys. Whereas NoSQL products are really good at writing things and retrieving one item from storage. When looking at redoing our architecture a few years ago to be more scalable, I had to consider these two issues. For what it is worth, the NoSQL market was not nearly as mature as it is now. So, my choices were much more limited. In the end, we decided to stick with MySQL. It turns out that a primary or unique key lookup on a MySQL/InnoDB table is really fast. It is sort of like having a key/value storage system. And, I can still do range based queries against it.<br><br>But, back to Dathan's problem: clicks. We store clicks at dealnews. Lots of clicks. We also store views. We store more views than we do clicks. So, lots of views and lots of clicks. (Sorry for the vague numbers, company secrets and all. We are a top <a href="http://siteanalytics.compete.com/dealnews.com/?metric=rank&months=12">1,000 Compete.com</a> site during peak shopping season.) And we do it all in MySQL. And we do it all with one server. I should disclose we are deploying a 
second server, but it is more for high availability than processing 
power. Like Dathan, we only use about the last 24 hours of data at any given time. There are three keys for us doing logging like this in MySQL.<br><br><strong>Use MyISAM<br><br></strong>MyISAM supports concurrent inserts. Concurrent inserts means that inserts can add rows to the end of a table while selects are being performed on other parts of the data set. This is exactly the use case for our logging. There are caveats with range queries as pointed out by the <a href="http://www.mysqlperformanceblog.com/2006/06/13/myisam-concurrent-insert/">MySQL Performance Blog</a>.<strong> <br><br>Rotating tables<br><br></strong>MySQL (and InnoDB in particular) really sucks at deleting rows. Like, really sucks. Deleting causes locks. Bleh. So, we never delete rows from our logging tables. Instead, nightly we rotate the tables. RENAME TABLE is an (near) atomic process in MySQL. So, we just create a new table.<br><pre>create table clicks_new like clicks;<br>rename table clicks to clicks_2010032500001, clicks_new to clicks;</pre>
<br>Tada! We now have an empty table for today's clicks. We now drop any table with a date stamp that is longer than x days old. Drops are fast, we like drops.<br><br>For querying these tables, we use UNION. It works really well. We just issue a SHOW TABLES LIKE 'clicks%' and union the query across all the tables. Works like a charm.<br><br><strong>Gearman</strong><br><br>So, I get a lot of flack at work for my outright lust for <a href="http://gearman.org/">Gearman</a>. It is my new <a href="http://en.wikipedia.org/wiki/Duct_tape#In_popular_culture">duct tape</a>. When you have a scalability problem, there is a good chance you can solve it with Gearman. So, how does this help with logging to MySQL? Well, sometimes, MySQL can become backed up with inserts. It happens to the best of us. So, instead of letting that pile up in our web requests, we let it pile up in Gearman. Instead of having our web scripts write to MySQL directly, we have them fire Gearman background jobs with the logging data in them. The Gearman workers can then write to the MySQL server when it is available. Under normal operating procedure, that is in near real time. But, if the MySQL server does get backed up, the jobs just queue up in Gearman and are processed when the MySQL server is available.<br><br><strong>BONUS! Insert Delayed</strong><br><br>This is our old trick before we used Gearman. MySQL (MyISAM) has a neat feature where you can have <a href="http://dev.mysql.com/doc/refman/5.1/en/insert-delayed.html">inserts delayed</a> until the table is available. The query is sent to the MySQL server and it answers with success immediately to the client. This means your web script can continue on and not get blocked waiting for the insert. But, MySQL will only queue up so many before it starts erroring out. So, it is not as fool proof as a job processing system like Gearman.<br><br><strong>Summary</strong><br><br>To log with MySQL:<br><ul><li>Use MyISAM with concurrent inserts</li><li>Rotate tables daily and use UNION to query</li><li>Use delayed inserts with MySQL or a job processing agent like Gearman</li></ul>Happy logging!<br><br>PS: You may be asking, "Brian, what about <a href="http://dev.mysql.com/doc/refman/5.1/en/partitioning.html">Partitioned Tables</a>?" I asked myself that before deploying this solution. More importantly, in IRC I asked <a href="http://krow.livejournal.com/">Brian Aker</a> about MySQL partitioned tables. I am paraphrasing, but he said that if I ever think I might alter that table, I would not trust it with the partitions in MySQL. So, that kind of turned me off of them.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Wed, 24 Mar 2010 00:20:12 -0500</pubDate>
            <category>gearman</category>
            <category>mysql</category>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/apache-logs-lua</guid>
            <title>Separating Apache logs by virtualhost with Lua</title>
            <link>http://brian.moonspot.net/apache-logs-lua</link>
            <description><![CDATA[By default, most distributions use logrotate to rotate Apache logs. Or worse, they don't rotate them at all. I find the idea of a cron job restarting my web server every night to be very disturbing. So, years ago, we started using <a href="http://cronolog.org/">cronolog</a>. Cronolog separates logs using a date/time picture. So, you get nice logs per day.<br><br>But, what if you are running 5 or 6 virtual hosts on the server? Do you really want all those logs in one file? You might. But, I don't. So, we ended up running a cronolog command per virtual host. At one time, this was 10 cronolog processes. Now, they are tiny at about 500k of resident memory used when running. But still, it seemed like a waste. Enter <a href="http://n0rp.chemlab.org/vlogger/">vlogger</a>. Vlogger could take a virtual host name in its file name picture. And it would create the directories if they did not exist. So, now, we could have logs separated by virtual host and date. Alll was good.<br><br>But, vlogger has not been updated for a while. It started spitting out errors, right into my access logs. And I could not find a solution. The incoming log data did not change. My only assumption is that some Perl library it used changed and broke it. So, here I am again with cronolog.<br><br>I decided I could just write one. So, I started thinking about the problem. It needs to be small. PHP would be a stupid choice. One PHP process would be more than 10 cronolog processes. I decided on <a href="http://www.lua.org/about.html">Lua</a>.<br><br>"Lua is a powerful, fast, lightweight, embeddable scripting language." It is also usable as a shell scripting language, which is what I needed. So, I got to hacking and came up with a script that does the job quite well. When running, it uses about 800k of resident memory. You can download the script here on my site.<br><br><a href="/vlualogger.txt">vlualogger</a> - 3.7k]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Sat, 13 Mar 2010 02:41:18 -0600</pubDate>
            <category>apache</category>
            <category>lua</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/php-progress-bar</guid>
            <title>PHP command line progress bar</title>
            <link>http://brian.moonspot.net/php-progress-bar</link>
            <description><![CDATA[Was just looking through some code and came across this function I wrote some time ago. If you do a lot of your processing scripts in PHP like we do, you probably need to know what is going on sometimes. So, I made a progress bar for use on the cli. I thought I would share it.&nbsp; <a href="http://www.screencast.com/users/brianlmoon/folders/Jing/media/822d9970-a6a3-4071-bdc6-1303cce9800a">Here is a video</a> of it in action. And the <a href="http://brian.moonspot.net/status_bar.php.txt">code can be found here</a>.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Wed, 10 Mar 2010 11:33:34 -0600</pubDate>
            <category>php</category>
        </item>
        <item>
            <guid>http://brian.moonspot.net/develop-for-production</guid>
            <title>Developers should write code for production</title>
            <link>http://brian.moonspot.net/develop-for-production</link>
            <description><![CDATA[Having development and staging environments that reflect production is a
 key component of DevOps.&nbsp; An example for us is dealing with our CDN. <br><br>I can imagine in some dysfunctional, fragmented company, a developer works on a web application and sticks all the images in the local directory with his scripts. Then some operations/deployment guy has to first move the images where they need to be and then change all the code that references those images.&nbsp; If he is lucky, he has a script that does it for him. This is a needless exercise. If you have a development environment that looks and acts like production, this is all handled for you.<br><br>Here is an example of how it works for us. We use a CDN for all images, javascript, CSS and more. Those files come from a set of domains: s1.dlnws.com - s5.dlnws.com. So, our dev environments have similar domains. somedev.s5.dlnws.com points to a virtual server. We then use mod_substitute in Apache to rewrite those URLs on the dev machine. Each developer and staging instances will have an Apache configuration such as:

<pre>Substitute "s|http://s1.dlnws.com|http://somedev.s1.dev.dlnws.com|in"<br>Substitute "s|http://s2.dlnws.com|http://somedev.s2.dev.dlnws.com|in"<br>Substitute "s|http://s3.dlnws.com|http://somedev.s3.dev.dlnws.com|in"<br>Substitute "s|http://s4.dlnws.com|http://somedev.s4.dev.dlnws.com|in"<br>Substitute "s|http://s5.dlnws.com|http://somedev.s5.dev.dlnws.com|in"<br></pre>

So our developers put the production URLs for images into our code. When they test on the development environment, they get URLs that point to their instance, not production. No fussing with images after the fact.<br><br>In addition to this, we use mod_proxy to emulate our production load balancers. Special request routing happens in production. We need to see that when developing so we don't deploy code that does not work in that circumstance. If the load balancers send all requests coming in to /somedir to a different set of servers, we have mod_proxy do the same thing to a different VirutalHost in our Apache configuration. It is not always perfect, but it gets us as close to production as we can get without buying very expensive load balancers for our development environments.<br><br>Of course, we did not come to this overnight. It took us years to get to this point. Maybe it won't take you that long. Keep in mind when creating your development environments to make them work like production. It is neat to be able to write code on your laptop. I did it for years. But, at some point before you send out code for production, the <strong>developer</strong> should run it on a production like environment. Then deploying should be much easier.]]></description>
            <dc:creator>brianlmoon</dc:creator>
            <pubDate>Wed, 03 Mar 2010 11:20:02 -0600</pubDate>
            <category>devops</category>
        </item>
    </channel>
</rss>

