Symfony

Symfony 2 requires PHP 5.3 and PDO, making Symfony 2 one of the most up to date PHP development frameworks in terms of requirements. The older Symfony 1.4 requires PHP 5.2.4 and might be a good choice if you cannot update PHP.

Download Symfony from www.symfony-project.org. There is an introductory tutorial and it is worth a read before installing Symfony. There a current 1.4 download and a preview of Symfony version 2, for which there might be less documentation. Symfony 2 is expected to replace 1.4 as the current product by the end of March 2011.

Requirements

Symfony 1.4 requires PHP 5.2.4 or higher but not 5.2.9. PHP 5.2 is the most common recent version of PHP. PHP 5.3 is rapidly replacing 5.2 and should be the minimum starting point for new projects in 2011. As a comparison, the Drupal content management system version 6 requires PHP 5.2 and the recently released Drupal 7 requires PHP 5.3. Symfony 2 uses PHP 5.3.2 or later.

Symfony uses PDO for database access, the same as Drupal 7 and other up to date software, giving you access to all the important databases, MySQL, INNODB, SQLite, and PostgreSQL. PDO requires an additional module for the specific database. For example, you install PDO-mysql for MySQL.

The PHP XML module is optional and the use is not specified so install it. You also need the PHP utf8_decode function that is supplied in the standard XML module. PHP 5 arrives with XML as a standard part of the install.

Symfony uses ORM, Object-Relational Mapping, and 1.4 gives you the choice of Propel or Doctrine. Propel requires the PHP XSL module. Doctrine uses YAML and might require the PHP YAML module. Symfony 2 uses Doctrine with no option for Propel.

Symfony requires the standard built in PHP Iconv and Tokenizer functions. You need the Multibyte module, something needed by almost all modern applications, but is not yet built in to PHP.

The PHP posix_isatty function is required to add colour to command line messages, a completely unnecessary feature. posix_isatty is part of the standard PHP Posix module installed by default but not installed by default on some of my computers and not available as an option on those computers.

session.auto_start is set to off in php.ini. When a PHP session starts, headers are sent to the Web browser that stop you from redirecting users to another page. Switching auto start off is standard for most Web sites. In some sites I use code to read the session in a way that still lets you redirect.

Your php.ini should have the standard defaults, short_open_tag off, magic_quotes_gpc off, and register_globals off. An ancient version of PHP had these settings on and I wrote extensively about the problems the settings caused. Eventually the PHP developers switched the settings off but some dinosaur software still expects the settings to be on.

A PHP code cache, commonly called an accelerator, is useful. APC is built into PHP 6 so use APC. APC is a one click install for PHP under Windows, just select APC in extensions. If PHP is already installed in Windows but not APC, select the Windows Control Panel, Add or Remove Programs, PHP, then Change.

Features

Command line interface?

Symfony list a command line interface as an advantage instead of a throwback to the days when dinosaurs had to use teletype. A command line interface is usually included in an application to make up for bad design or lack of development or as a comfort factor for people raised in the caves of 1980s Unix or 1970s DOS.

Copying everyone else

The propaganda for Symphony 2 is a long string of just like ... where ... is often Java or something designed for Java. Java code is inefficient because of the limited data types and PHP code kills Java for efficiency when tested in comparable situations using the easiest to write code for each language. Artificially restricting PHP code to Java emulation is not good practice.

Java is so difficult to teach that most teachers resort to code templates commonly called design patterns. I suffered through one term of that rubbish at one university. If you start with a proper design for the language you are going to use, they type of data you use, and they way the data is used, the PHP design is easier because you can use data types to match your data, the PHP code is easier for the same reason, and the result is faster for the same reason.

Copying Java and Java applications might be an advantage when you sell a framework to a company already using Java but it is not the best choice for everyone else. Witness the success of all the PHP based applications not emulating Java.

Environments

Symfony 2 arrives with predefined environments for several stages of application development, development, test, staging, and production. Test and staging overlap with Q&A, depending on your development process. Test is usually testing for functionality and then passes to end user testing. Staging is often volume testing for performance then for training.

MIT license

Most open source applications restrict you to the GPL or a similar license, ensuring you have free software but are not free to use it your way. BSD and MIT style licenses also give you the freedom to use software your way, including building commercial applications on top then distributing the result as your product.

ORM

ORM is a good idea when using a variety of databases because ORM lets you define the data layout once then apply it to the chosen database then switch to another database later without redefining data. Symfony 1.4 gives you the choice of Doctrine or Propel, while Symfony focuses on Doctrine.

Propel is oriented toward performance. Doctrine is oriented towards features. Some people start with Propel then switch to Doctrine when they develop complex databases. Others switch from Doctrine to Propel because Doctrine is too slow. Beginners will have more success with Doctrine because Doctrine has better documentation.

Performance tests show some queries are similar in both products while other queries can be five or ten times slower in Doctrine. Propel is, in turn, slower than feeding SQL direct into PDO. There are ways to make Doctrine queries faster. Both Doctrine and Propel have new releases with significant changes. Propel 1.5 is slight faster than 1.4 for similar queries and slightly slower when you use the extra features in 1.5. There is a Doctrine 2 that is faster but nobody is publishing speed comparisons.

Given the speed difference, I am happy to write queries direct in SQL to bypass the ORMs for frequently used queries. I might try Propel 1.5 first if the documentation is improved.

PDO

Symfony uses PDO for database access. PDO works with all the important databases, MySQL, INNODB, SQLite, and PostgreSQL. PDO also works with the expensive Oracle and with less expensive commercial alternatives. PDO gives you basic database compatibility but you still have to write different SQL for each database when performing complicated operations. Some databases default to non standard date formats and require special settings to force standard dates in SQL.

Profiler

When you are testing, you can get a quick useful summary from the Symfony Profiler tool. The tool overlaps Firebug and some other tools.

Speed

Symfony claim Symfony 2 is three times faster than Symfony 1.4 and publish two speed tests, one showing 2 as 2 times faster than 1.4 and the other showing 2 is 2.5 times faster than 1.4. Neither speed test uses a database, the critical issue now they offer only Doctrine.

The same speed tests show Symfony 2 is faster than a lot of other frameworks but only when not using a database, an almost useless comparison.

Twig

There are a heap of output template programming languages and Symfony uses Twig. Many claim to eliminate programming then proceed to demonstrate how you program using their language. Symfony offers Twig and PHP as two equal alternatives and both produce the same result with a similar effort and similar code within the boundaries of what Twig can do. For anything more complicated, PHP is the choice and can be wrapped around Twig.

Symfony uses the Model View Controller approach, the templating should be in the view and everything else should be in the model or controller. Any complex data handling should be outside the view, outside what Twig does, but complex dynamic themes require a lot of changes in the view, resulting in most of the themeing occurring in the controller instead of the view. Effectively you have a view assembling a bunch of other views. In Symfony with Twig, each individual view can be Twig or PHP based.

Web Debug Toolbar

This is a nice debugging tool to use along with Firebug and a couple of other tools.

Other considerations

The Symfony introduction tutorial shows a session based on cookies instead of a database. There is very little in the introduction about databases and a modern application, Web or not Web based, is useless without a database. You have to test Symfony through to the point of creating a database with several tables and some joins before you find out what Symfony is really like.

The same introduction shows many little control files with the control files written in PHP, XML, and YAML. XML makes sense for some things but not for general use as a control file language. YAML looks like an interesting attempt at a control file language. There are some things that are too complicated for YAML or XML and have to be written in PHP. You do not want half your application in PHP then part in YAML and part in XML. PHP has the best features for speeding up interpretation and should be your first choice with XML used only when supplied from an external application.

Alternatives

CakePHP

CakePHP is a framework started around the same time as Symfony. The CakePHP Web site is more complex than the Symfony Web site and is slower in in some parts. It is hard to tell if it is CakePHP or the content or the server making the Web site slower. CakePHP has an impressive list of reference sites and many of them work far better than the CakePHP site.

I have looked at CakePHP in the past for several projects and gave up. CakePHP is, like several of the alternatives, about to launch a brand new version than might be better. The new CakePHP version 2 lifts the minimum PHP requirement from 4 to 5.2, bringing CakePHP up to Symfony 1.4 and Drupal 6 but not up to Symfony 2 or Drupal 7. If you use CakePHP, start from version 2.

CodeIgniter

CodeIgniter is designed to be small, lightweight, and fast. CodeIgniter has lots of reference sites and many are fast. CodeIgniter can work direct with databases or through Doctrine. CodeIgniter version 2 is already out and has PHP 5.1 as the minimum requirement. (PHP 5.2 has some serious improvements so use the latest 5.2.)

DooPHP

The new kid on the PHP framework block. Fast compared to the other frameworks over a year ago, it needs comparison to all the new versions of the other frameworks. Lots of relevant features but beginner level documentation is missing for many of the features.

Horde

Horde is a framework and is supplied with some ready built applications including an email application. There are people using the prebuilt applications. I do not know anyone using the framework for new applications.

Kajona

Kajona started in German and is now in English plus a few other European languages. The API documentation is excellent as is the ready to use administrative interface. If you want a framework and want a shortcut into a working Web site, choose Kajona.

Kohana

Kohana was originally based on CodeIgniter and has some similar characteristics. Kohana uses HMVC instead of MVC, allowing the splitting of a Web page presentation into a lot of little presentations, similar to the way Drupal handles pages when using blocks or the way you might build a page for Web 4. (Request my Web 4.0 presentation for your next conference, board meeting, or a workshop for your marketing and IT areas.)

Lithium

Lithium is a branch from CakePHP. Lithium is a rewrite to use PHP 5.3 and almost every new feature of PHP. Some of those new features have a big performance impact and one of the reasons some other frameworks went the other way.

Qcodo

Another framework with some impressive reference Web sites.

QCubed

QCubed is a branch of Qcodo with jQuery replacing a lot of custom Javascript.

Seagull

Compatible with the ancient PHP 4, Seagull looks like a fancy packaging of the old PEAR stuff with some sample code to create example applications. It is obsolete.

Yii

Yii claim their framework is fast, secure, and professional. Some of the other frameworks show benchmarks against Yii and Yii is middle of the road, not fast. Yii use a coding approach known variously as ONCE, DRY, DIE, and SSoT. You write code once then use it everywhere without repetition. Taken to the extreme, you end up with a lot of little functions calling each other and a significant overhead from the function calls, removing the option to be a fast framework.

Zend Framework

Zend Framework is going through a rewrite for a version 2 to, in part, remove some of the stupid ideas from version 1. The changes for Zend Framework version 2 have some parallels to the changes in Symfony version 2. One advantage of Simfony over some other frameworks is the ability to work with the Zend Framework.