Why Use a PHP Framework?

At last night’s NY-PHP gathering, a fellow PHP’er and I discussed PHP frameworks. I told her I was developing an e-commerce site using Zend Framework. She replied that she’d been considering frameworks, especially Cake and Symfony, “but I’m not sure I need a framework at all. I write my own SQL; my apps work fine. What would a framework do for me?”

Setting aside the differences between PHP frameworks, I’m aware of at least 4 reasons to use them:

  1. Modular design: A home-grown application, with its ad hoc growth, can become a tangled mess that’s hard to change or enhance. Most mainstream frameworks provide a modular design that makes it easier to modify or add components.
  2. Flexible components: Sure, you can write your own authorization class in PHP, but why reinvent the wheel? The framework will provide an integrated component that handles not only your current needs, but requirements that you haven’t yet encountered (but that the framework’s community has). With a framework, chances are that you won’t have to redesign your authorization system when the users ask for something new.
  3. Best practices: As you use the framework, you’ll begin to absorb the practices and (we hope) good habits of the framework’s creators.
  4. New capabilities: Frameworks regularly add functionality to help developers implement new technology. These days, common enhancements involve AJAX and connections to the APIs of popular web service providers.

Developers may understandably wonder if mastering a framework is worth the learning curve. In my opinion, the effort to learn a framework will be repaid with applications that are well structured, flexible, and easily maintained.

This entry was posted in IT, PHP, Web development. Bookmark the permalink.

3 Responses to Why Use a PHP Framework?

  1. Nic Appleby says:

    I’m wholly in favour of using a framework. I’m just wondering about the order of the performance hit vs. a straight php application? Do you have any thoughts on whether it is noticeable, or whether the framework’s benefits outweigh the performance hit?

    • Alan Seiden says:

      Nic, good question. Yes, frameworks carry overhead that affects performance. For me, the benefits are usually worth the performance hit, but if the slowdown is unacceptable, I can make more efficient use of the framework or even customize/streamline the troublesome components.

      Framework developers aren’t oblivious to performance concerns. For example, Zend Framework’s developers addressed these concerns in version 1.70. It runs much faster than previous versions and includes a performance guide for developers needing more speed.

      I’m also a fan of caching. Many frameworks provide caching mechanisms that add back some of the performance.

      In conclusion, although frameworks will always be slower than raw, hand-tuned code, they can provide decent performance, and even good performance with a little effort.

  2. Hello Alan, hello Nic,

    I agree, that many framework developers are not aware of performance issues. A reason for that may be the availibility of byte code caching or other tools to store information (e.g. application caching, memcached, …). But this is not true for everyone. Especially, the APF is designed for best performance (see http://adventure-php-framework.org/Page/103-Yii-vs-apf/~/sites_demosite_biz-action/setLanguage/lang/en). Combined with a rich featureset (see http://adventure-php-framework.org/Page/088-Why-apf/~/sites_demosite_biz-action/setLanguage/lang/en), the APF is worth a try!

Leave a Reply

Your email address will not be published. Required fields are marked *

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