Best practices in PHP development

I didn’t go to ZendCon this year, but I just finished reading Mike Naberezny’s and Matthew Weier O’Phinney’s PHP Developer Best Practices, and it’s a pretty good compendium of what to do if your organization is developing in PHP, or perhaps you’re working on a project that has potential to attract more contributors and maybe even grow into a company.

  1. Use source control
    1. First, choose between distributed and non-distributed
    2. Then, if you chose non-distributed, choose between CVS and SVN
    3. In Subversion, use trunk/ for ongoing development and bug fixes, branches/ for ongoing large projects that later need to be merged in, and tags/ for releases
    4. Use svn externals to connect to remote repositories
    5. Subversion supports pre-commit and post-commit hooks for better code maintainability and checks
  2. Implement coding standards
    1. Develop class, variable, function, package, etc. naming conventions
    2. Agree on common formatting as far as spacing, braces, etc.
    3. Implement comment standards
    4. PHP_CodeSniffer can run on pre-commit to check whether the commit adheres to the standards
    5. Don’t forget to enforce coding standards on any outsourced projects
  3. Unit testing and code coverage
    1. Use PHPUnit for unit testing
    2. For continuous integration, check out phpUnderControl
    3. For integration testing, check out Selenium, a general Web application testing suite
  4. Documentation
    1. Don’t invent your own standards, see what phpDocumentor has to offer. Doxygen also supports phpDoc tags
    2. For documenting the software project, try DocBook - XML-based format that allows you to quickly publish a PDF document, or a Website with documentation
  5. Deployment
    1. Have a standard deployment process that a rookie can familiarize with quickly
    2. Support 3 environments - development, staging, and production
    3. Deploy code only from repository tags, don’t run trunk, or allow code editing on server
    4. Check out a new tag from SVN, point the symlink to it. If something goes wrong during release, change the symlink back to the previous version - easy rollback strategy
    5. Everything that needs to be done on the production servers needs to be automated
    6. You can do another Selenium test after the release is deployed
    7. Check out Monit and Supervisord for deployment monitoring
Posted in PHP, Programming at September 16th, 2008. Trackback URI: trackback

2 Responses to “Best practices in PHP development”

  1. September 17th, 2008 at 2:19 pm #Pavel

    Do you know if audio/video versions of those presentations are available?

  2. October 3rd, 2008 at 1:20 am #Weekly linkdump #145 - max - блог разработчиков

    [...] Алекс Москалюк пересказывает тезисы книги PHP Best practices, Best practices in PHP development - alex.moskalyuk [...]

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>