PHP

Slides for my php|tek talk: “No Really, It’s All About You”

I’ve put my slides for my framework presentation from this year’s php|tek conference – “No Really, It’s All About You” comparing CakePHP, CodeIgniter, Solar and the Zend Framework – up on Slideshare:

Unfortunately, no one was there to record the resulting “discussion” that came from the questions after – heh.

Working towards a better deployment (Part 4)

I’m back with the fourth part of my look at deployment of PHP applications to focus on the actual deployment technologies. I’ve already talked some about version control, build tools and unit testing in the previous parts of the series and this new information should round it out nicely with a simple approach to the push part of the deployment.

As it stands right now, the final step in our deployment is one of the simplest. We have some bash scripts that are aliased to rsync commands for pushing files out to each of our different sites. Since the assumption is that anything that’s in the QA/staging area is good to go, the rsync commands take everything that’s out on production and, if there’s any differences, overwrites the remote version. It’s light, simple and makes it easy to push out an entire site in one go. Things can get a bit tricky of you only want to deploy a portion of the site at a time though. There haven’t been many cases where we needed to do this, but it would have been nice to have a way to break it up a bit more.

I posted two TwtPolls in the past few days asking some of the other developers in the community (some outside of PHP too) about which method they preferred for deploying their sites out to a production server. Here’s the results of the latest poll (hopefully it’ll stick around for a while – I’ll mention the numbers too, just in case).

There were 45 votes total on ten different options…here’s how it came out:

FTP/SFTP [ 20% (9 votes) ]
SSH/SCP [ 4% (2 votes) ]
RSYNC [ 9% (4 votes) ]
SVN (via ssh or export) [ 49% (22 votes) ]
Capistrano [ 7% (3 votes) ]
Ant [ 2% (1 votes) ]
Cut & Paste [ 2% (1 votes) ]
Other Manual Process [ 2% (1 votes) ]
Other Automatic Process [ 2% (1 votes) ]
A mashup of several [ 2% (1 votes) ]

As you can see rsync, our current choice, only came in third under FTP/SFTP and the overwhelming favorite, Subversion deployment. Some of them choose to make the copy of the code on the production server a checkout of the current version (svn up when it needs refreshing) and some export from their current version and push those files out. Unfortunately, we’re still stuck with CVS for the time being (coming soon, hopefully!) so working with branching, tagging and all should be quite a bit easier.

This final step can either be a manual one (how we do it now) or as a part of another process (how I want to do it). I currently have a final step in my Phing build file that, if all goes well during the build, will call one of our bash scripts to push the code directly from there. This helps to keep things nice and tidy and makes it a simple “single process” tool that sysadmins or QA folks can use to ship out the code that’s been cleared for public consumption.

Now that I’ve gotten to the end of the descriptions on all of this stuff, let’s head back to the beginning and look at some of the actual code, configurations and technologies related to deployment. I’ve seen some good suggestions as to a step I’ve been missing – optimization. Keep an eye out for this first in the “Deployment Tech” series, a continuation of this general look at deployment of PHP applications.

Working towards a better deployment (Part 3)

So, on the to third part of my little series (part one, part two) on making a shiny new deployment system for our sites. What’s that? Yep, I said sites – plural. I’m working all of this up on a “one site” concept, but in reality we have five or six websites that this process will eventually apply to. They’re all pretty similar, thankfully, and all use a lot of the same libraries. This makes the next step of my little process so much easier – the unit testing.

If you’re not unit testing your code, drop what you’re doing (well, finish this article at least) and go learn as much as you can about it. It can help take that feeling of dread away from your code updates and can help make things go a bit smoother in your deployment. Imagine having an automated way to check and ensure that the results of your scripts/libraries are still working exactly how the should. Unit tests can help you verify that things that should pass the tests still do and that your failures still fail in all the right ways.

One of the more popular unit testing softwares out there is PHPUnit (from Sebastian Bergmann). Its a super-easy way to set up a suite of tests that can be run as a part of your deployment process. The tests run on your scripts with methods corresponding to each of the methods in the target class. You use assertions inside the tests to check for things like pass, fail, true, false, if an array value is set, etc. The methods are called and the output is verified – if everything’s good, the test passed. If there’s a problem (something non-standard) the test fails which can cause the entire build process to fail too.

You can test more than just simple single method calls too. Say you have a class that creates a user by logging them in and setting up a session for them. If your tests require this, you can make the user session in your “setup” method and use the “teardown” method once things are finished to log the user out and destroy any of the resources you might have created.

These unit tests have found a home in my build process right after the lint check on each of the new files. Phing allows you to defne a tests directory for it to look in for any unit tests it should apply. The PHPUnitTask takes care of the dirty work with options to fail the build if the tests have an error and gather code coverage information as they’re tested. You can also set up a PHPUnitReport task to get more information out of your build. This makes reports and, with the help of some XSLT templates, transforms the results into something n bit more human readable.

All that’s really left after this (with the exception of a few other options) is the push of the up-to-date, tested code out to the production server…but that’s for the next article to cover.

Oh, and for those that are wondering, I’m going to be getting to the tech behind all of this pretty soon. Having information about the setup is one thing, but having the actual setup behind it all helps even more. I’m going to go back over all of this from start to finish to show you how it all fits together. Just hang in there with me!

Working towards a better deployment (Part 2)

In the previous part of this series, I looked at some of the current methods we use for code development and deployment as well as some of the goals I put out there for myself in the quest to find a good deployment system that would work for us and our code. I’m back again to look at the next part of the process – the build.

Once you have the process defined for the developers to follow, you need to lay the foundations for the administrator to handle the rest of the process. Once we know that the code is good and all is right with the world, the deployment phase can get started. Ideally, the admin shouldn’t have to do much at all – well, besides making sure the right code gets merged into the trunk, that can be a little tricky. A correctly defined process should handle the rest, though – running tests on the code to ensure correct functionality, locating any syntax errors it might have, etc – all automagically.

The tool I’ve chosen to act as a base for all of this is Phing, a build tool based on Apache’s Ant that uses XML config files and PHP classes for its “tasks” (both interfaces with external programs and internal data handling methods). This is a perfect setup for PHP deployment and makes it simple for just about any admin out there that’s even vaugely familiar with PHP to extend. Our Phing setup has four goals:

  • Grab the latest version of the repository after its been through QA
  • Run a lint check on it to ensure there’s no syntax errors
  • Run a series of unit tests on the code
  • And, if there were no errors, deploy the code out to production

Each of these steps have the “failonerror” value set to true, so the build will fail if even one check is wrong (and, come to find out, unit tests marked incomplete will cause failures).

Despite what the current Phing documentation says, there is a task for CVS integration that lets you run commands and define parameters. Our first step uses this to check out a clean version of the code to a working directory. Since the build is run as the dedicated web user on the machine, the permissions should be correct, but I used an two exec tasks to ensure the owner and group settings were right. I had to do a little hackery here to keep things a little lighter. My next target (action) in the build file is to lint the files to be sure they don’t have syntax errors. Unfortunately, by default, this would check everything in our repository. The files for our external site don’t number too many, but our internal site with several applications and documents inside is quite a bit larger. This resulted in the linting process to take quite a while and make the build process up to five minutes long.

The hack come in on the CvsTask file that’s included with Phing – I modified the code to find only the files that were updated in the latest “cvs update” call and return that list back to the build to loop through with a foreach. This saves a ton of time and only checks the files that need it – just the files that have changed. We’re just looking for syntax errors, after all.

Next up is unit testing…more to come!

Working towards a better deployment (Part 1)

Since we’re in the “slow time” for the business I work for (no one cares about their natural gas bill when it’s warm and the price is right) I’ve taken some of the flexible time I’ve found to work on a pet project of mine – the overall well-being of our development process.

Let me start off by mentioning what our current setup is:

  • We use CVS as our version control repository not so much by our choice now but by the choice of someone many years back. It’s worked well for what we’ve needed it for, but we’re going to be upgrading to Subversion here pretty quickly.
  • We have separate development, QA/testing and production environments so that each developer can work in their own space and have a QA to push it to so there’s no testing on the devs.
  • Code pushes are done with rsync directly from the QA environments out to production.

That’s pretty much it – a simple process that has worked pretty well for the six years I’ve been with my current employer. Unfortunately, times change and so do development standards. When I first started there were only two of us that worked on the code for both the internal and external websites. Now that team has grown to include at least six others. Needless to say, keeping things straight has become a bit more difficult.

So, back to my “free” time – I stepped back and took a look at our process. I tried to find out what could be improved in it and what was completely missing. What we have is a good base to start from, but there were a lot of other things to consider like quality of the code being pushed, checking to be sure there’s no syntax issues, creating a standardized way for the code to flow and what tools might be best for the job.

I’ve told you what we currently have, so let me tell you where my goal is – I want a system that allows the developers to work on both the main trunk and any branches (for projects and the like) of code quickly and easily and one that, once it’s been committed and tested, is out of their hands (right now, we have a system in place that lets developers push bits of code to production – a definite bad idea). Developers would have the option to change database connection information as they see fit but still have defaults for all to use. We have multiple customer databases and the location of the test databases isn’t always the same.

Once the developer is satisfied with the code and feels it bug free (enough), they can commit it and send it on its way for testing. That’s where their job ends – from here the administrator’s role kicks in. They’re the one that has the cvs-foo (or svn-foo) to pull the code out of the branch and push it into the currently checked out code in the QA environment. This code can then be reviewed and tested by whatever group needs to without interfering with any updates the developer might be working on. Once testing is complete and everything’s good to go, that code can be commited back to the trunk, pushed to a staging area and synced out to the production site. I don’t believe that QA and the base for deployment (staging) should be the same – it’s just too confusing when you could have a merging of codesets from branches all over the place. If you’re going to sync, sync from an up-to-date version of the code.

Which leads me to my next point….the build process. (the next part of this series will cover it)

A Shinier New Joind.in

In one of my previous posts I mentioned a little pet project I’ve been working on. I had an initial version out the door and things were working pretty well. It needed a little something else, though. The layout was functional, but not so easy on the eyes. I put out the call to see if there was anyone out there that might want to lend some time to giving the site a bit of a touch-up and, thankfully Jan Sorgalla answered the call.

He’s been working over the past few weeks on a new look and feel for the site to bring it up to that next level. Personally, I think he did an excellent job in both integrating some of the flow of the previous version of the site with a better styling to make the site more usable.

Development on the site is still continuing and more new features are in the works. The system is open to any events, not just PHP-related, out there that might want to have make their lives easier by letting attendees give the speakers their feedback directly.

Check out the new site!

Speaking at php|tek 2009 – “No Really, It’s All About You”

Now that the schedule is official and all, I suppose I can post about it – I’m going to be presenting at this year’s php|tek conference (in Chicago) on a developer-centric approach to frameworks – No Really, It’s All About You. Here’s the summary:

You’ve heard it all before – this framework can do this, this other one can do it faster. The lists of features and comparisons go on and on, but there’s one thing those lists forget – the human element.

Frameworks are only as good as the developers using them and in this talk I’ll focus on these developers and how they interact with the tools. How easy is it to create an application in CodeIgniter? What kinds of things does Solar make simpler than others? Is the Zend Framework the best choice for some of the more ‘business applications’?

I’ll take a developer-centric approach to four popular PHP frameworks: CodeIgniter, CakePHP, Solar and the Zend Framework. Topics include speed of application development, how simple they make the simple things and maybe a few benchmarks thrown in for fun.

This will be my first time presenting at a conference and, really, my first time up in front talking about a technology topic. I haven’t had much experience in public speaking so a lot of it will be new to me. Oh well – what’s life for if not for taking those big jumps into the unknown.

So sign up already and come out to Chicago to see myself and lots of other qualified speakers talk about Subversion, streams, the SPL, security and much more…

Branching Yourself

If there’s one thing I don’t understand about programming communities (online and average joe coder on the street) it’s the competition that’s everywhere. Sure, I can see how there’ll always be the zealots that think their language can do everything. Well, I hate to break it to you guys but there’s just no such thing. Every language has their own feature set and their own strengths. There’s not one that’s going to work in all situations.

Repeat the mantra after me: “Use the right tool for the right job”.

Now, I’m a PHP developer so my views are a bit slanted that way, but I’ll be the first to admit that there’s things that the language just isn’t good for. I like to get feathers ruffled as much as the next guy, but there comes a point where you just have to concede. PHP is excellent for web development – it makes creating sites easy and there’s some great frameworks built on it but there are things it just doesn’t do well. Other languages like Python and Ruby are a bit more modular and, according to what I’ve read, and do a lot of the same things for the web that PHP does. There’s one thing to remember, though – it’s not really about what they do that’s the same, its the differences that matter.

You a Ruby developer can argue with the PHP developer all day long on how one handles objects versus the other or the “dumb syntax” that the other uses, but remember the mantra. There’s things that Ruby does that PHP just doesn’t do well and vice versa. Focus on these other things – that’s why you choose one language over another.

Don’t let your language choice get the better of you and put blinders on – expand your horizions! Don’t be afraid to check out other languages/technology/etc. You might actually learn something in the process that can make you an even better developer than you are.

Direct Feedback is a Good Thing: Joind.in

So, a few weeks back Keith Casey and I were talking about conferences and feedback. One thing we both (and various others that happened to be in the #zendcon IRC channel at the time) agreed on was that paper slips and verbal polls just aren’t the way to go when it comes to providing feedback to speakers on how they’re doing.

Automation is the way to go – bring the attendees directly back to the speakers and let their voices be heard. Obviously, a web site is the medium of choice and so I present to you Joind.in.

Joind.in provides the missing link between the people attending a conference and the ones that presented. The usual method of handing out paper forms is outdated and needs to be replaced. That’s where we come in – attendees can post their comments directly to each of the talks they attended, giving the speaker direct feedback on how they did and what they can do to improve. Joind.in also has something to offer the speakers – you can track your record across the conferences and see how changes in your talk might have made a difference in your ratings.

Things are still running in beta mode right now as I work out some of the kinks with both the code and with the interface (any designers that want to help out and contribute a few ideas, drop me a line), but I’m hoping that this can become a great asset for the speaking community – and not just the PHP one.

The idea is to make it as open as possible to allow for conference planners from any topic to come in, add their events and talks to get direct feedback from their attendees.

Here’s a list of a few of the stats for the site:

  • It runs on the CodeIgniter framework
  • It allows for “stubs” for conference names (ex. http://joind.in/event/phpapp08 for PHP Appalachia ’08
  • Speakers can “claim” their talks from each event and see how the same talk did at various events
  • The commenting system supports both public (viewed by all) and private (viewed by speakers and conference admins) comments

I am always open to suggestions about the service, so if you have comments either leave them on this post or submit our contact form.

Dallas PHP User Group on Twitter

My local user group (the Dallas PHP User Group) has added a twitter account to its list of contact methods. Meeting updates and other random group-related bits will be posted there.

If you’re a PHP developer in the Dallas, TX area, head over and follow us on Twitter to keep up with the latest.

We have a meeting tonight at the usual place with a presentation from Adobe. They’ll be talking about their technology for Rich Interfaces (like Flex and AIR) and combining them with the Zend Framework. Danny Dura will be presenting. The meeting starts at 7pm – hope you can all attend!