The major frameworks can be overkill for many PHP development projects. These 10 lightweight solutions have minimal resource and time requirements.
Using a framework makes the development process faster, more secure, and more enjoyable. However, a developer who uses a major framework, such as the Zend Framework, Ruby on Rails, and Grails, must invest time in order to understand the particular approach embraced by each solution. Additionally, they come with a number of bells and whistles that may never be required in many of your projects.
The Rails community recognized this quandary early on, creating alternative solutions such as Camping and Sinatra, which continued to embrace the framework approach, yet minimized both the resource requirements and time investment. Although often referred to as lightweight frameworks, in reality such solutions are quite capable of implementing a great many projects that would have otherwise been built using Rails, which might have been overkill for smaller, less-complex projects.
Recently, the lightweight framework movement has been catching on within the PHP community, with a great many lightweight frameworks beginning to gain followings. In this article I'll introduce the 10 best examples I've found of these solutions. They should at least serve as a jumping-off point for doing further investigation.
Although all of the lightweight frameworks attempt to position themselves as the fastest and least intrusive, perhaps no other does so more explicitly than DooPHP. Presenting a series of benchmarks that claim to lay waste to high-profile frameworks such as CakePHP and CodeIgniter, the DooPHP website identifies the framework as being "the fastest MVC-based PHP framework," while still managing to offer an impressive array of features including authentication and authorization, front- and back-end caching, and a RESTful API.
The DooPHP website offers a fair amount of documentation, including tutorials and an API reference, in addition to several demo applications.
The PHP Fat-Free Framework is the only one on my list that was built specifically to take advantage of PHP 5.3-specific features. Weighing in at just 42kb, it's also the smallest, a feat accomplished by bundling features into three separate modules, or "packs." The Core Pack contains the minimal set of features required to construct a website, including a router, HTML forms processor, template engine, and development tools such as a code profiler and unit testing suite. An optional Database Pack adds database interaction capabilities via the Fat-Free Axon ORM. Finally, an optional Expansion Pack bundles together a number of useful extensions, including a CAPTCHA generator, thumbnail generator, sitemap generator, and other useful features.
Kohana began life as a fork of the popular CodeIgniter framework. However, the 2.0 release was a complete rewrite of the codebase, which exclusively supported PHP 5. In addition to the strict support for PHP 5, Kohana differentiates itself by advertising easy extensibility, a rapid development cycle, API consistency, and an intuitive ORM interface. Further, a module ecosystem has begun to flourish, with almost 60 projects currently available on the site. Interestingly, several projects are ports of components found in the Zend Framework, such as the Zend ACL project.
The Limonade website names the aforementioned Camping and Sinatra frameworks as sources of inspiration. It's perhaps the most compact of the solutions described here in terms of the amount of code required to build something useful, with powerful demos such as the Wikir wiki (written in under 200 lines of code). But perhaps the most powerful evidence of Limonade's minimalistic approach is the example included with the project README, which includes all of the code necessary to power a one-page website:
return 'Hello world!';
Apparently the Recess developers and I went to different elementary schools, as my recollection of recess resembles something more akin to a scene from "Lord of the Flies" than the fun and delightful experience that apparently prompted their namesake framework. Either way, the developers have clearly worked hard to make the Recess user experience a fun one from the beginning, starting with a well-designed website consisting of well-written documentation and a number of tutorial-based screencasts.
In addition to supporting standard features such as REST, ORM, and custom routes, Recess offers a number of unique features such as modular support similar to that found in Django, in addition to diagnostics and a GUI-based wizard named Recess Tools that helps new users easily build their first Recess-powered application.
Orinoco identifies itself as a "full stack yet lightweight MVC framework." Like the other solutions discussed in this article, it offers customizable routes and an integrated ORM solution. Although development activity seems to have tailed off in late 2009, I've opted to mention Orinoco as the companion tutorial seems to indicate that a portion of the accompanying source code serves as an interesting example of how to create a simple ORM solution. Hopefully we'll see further project activity in 2010!
7. No-Framework PHP MVC Framework
Although the "framework" mentioned here isn't an official project, and in fact is the outcome of an argument against using frameworks by none other than PHP project founder Rasmus Lerdorf, I thought it sufficiently interesting to mention because Lerdorf actually demonstrates the power of PHP by using a blog entry to create a lightweight framework, which he calls the "No-Framework PHP MVC Framework." The post offers some rather interesting insight into how you can easily create powerful framework features using relatively short snippets of PHP code. It's well worth reading given the source.
8. Simple PHP Framework
It's fortuitous that the Simple PHP Framework alphabetically follows the aforementioned No-Framework PHP MVC Framework as the latter apparently was the inspiration for the former, with Active Record support thrown in for good measure. Although no documentation currently exists, project founder Tyler Hall mentions its adoption within Yahoo! for an unnamed project, making Simple PHP Framework worthy of inclusion within this list.
The Yii framework is the brainchild of Qiang Xue, the noted developer behind another popular framework named Prado. The founder leveraged his considerable experience and knowledge to create and foster this high-profile project. Accordingly, although classifying itself as a lightweight framework, Yii is packed with enterprise-level features, among them theming capabilities, unit and functional testing integration, logging, and the ability to generate code and manage websites via a console interface.
Although less than 2 1/2 years old, Yii already sports an active extension repository consisting of 200 extensions. Among them you'll find solutions for adding a WYSIWYG editor, integrating jQuery widgets, and even turning Yii into a content management system.
Unlike most of the other frameworks discussed here, the Yii developers highlight a long list of websites powered by the framework. Peruse this list to obtain a better understanding of the framework's capabilities.
10. Zend Framework
Surely I included this entry by mistake. right? With the 1.10.3 minimal release weighing in at 31MB (roughly 738 times larger than the aforementioned Fat-Free framework), how could the Zend Framework possibly be considered lightweight? I've included the Zend Framework precisely to clear up a common misconception about at least some of the more established framework solutions: its "use-at-will" architecture means you should think of the Zend Framework more as a smorgasbord buffet. Although almost 100 components are bundled with the framework, you aren't required to even use it as a framework in the traditional sense. Instead, you can selectively take advantage of components as you see fit. For instance, the Zend_Mail component happens to offer a pretty convenient solution for formatting and sending e-mail, meaning you can simply incorporate that standalone component into your custom web application (or for that matter, an application running any of the frameworks mentioned in this article).
In fact, one of the lightweight frameworks described in this article will suffice for the implementation of one of your projects, consider regularly perusing the Zend Framework Reference Guide for easy ways to implement features not yet offered by your selected framework -- saving you even more time!
True to the community's roots, PHP developers around the globe have once again managed to offer users more solutions than can be counted on an Oregon logger's hands. With so many possibilities, surely one of the aforementioned frameworks will strike your fancy. If not, or if you've found another solution, tell us about it in the comments!
About the Author
Jason Gilmore is the founder of EasyPHPWebsites.com. He also is the author of several popular books, including "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and ""Beginning PHP and MySQL, Third Edition".