Thứ Năm, 27 tháng 1, 2011

Top Open Source PHP Frameworks

After RoR there are lot many frameworks in PHP which are either inspired by it or based on MVC pattern. Today I am throwing some light on some of it, which I came across (I mean heard) during my development experience in PHP. Here I am talking about next generation Open Source PHP frameworks which I came across.
Symfony: Now it is more then 2 year old project and seems to be quite complete in the sense of feature and documentation. Symfony has quite rich documentation and community support. Their development seems to be really active as I see many change-sets getting committed and bugs getting fixed every Monday. Today Symfony 1.0.12 is released and Symfony 1.1 is on the way to getting released. I have not tried any project with Symfony as of yet but have been keeping a close eye on their activity since long and now when 1.1 release is near thinking of start something with it. 1.1 version will come with quite a lot welcome changes and I am looking further to it. Fabien Potencier and his team gave great contribution to the PHP world by gifting Symfony framework.
Symfony is MVC architecture based PHP framework. It is more of less inspired by Majovi and Ruby on Rails. Symfony team is not trying to reinvent the wheel and framework uses many opensource components in their base. For beginners it is little difficult to begin with Symfony but great deal of documentation and 21 days of askeet tutorials will help them out really.
I believe Symfony is really enterprise level framework. It has great deal of documentation and The Book (Definitive guide to Symfony - Open source)
Symfony uses Propel as default ORM and it has Doctrine Plugin in case if you wish to replace Propel. Symfony has 2 real world powerful application Yahoo Bookmarks! and preview.delicious.com. Symfony is having quite comprehensive plugin repository too.
I am looking forward to get my hands on it in near future.
Compatibility: PHP 5.2+

CakePHP: Another RoR inspired framework for PHP. It is called a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Cake is having 1.1 release as stable and they are in their beta of 1.2 version which suppose to have many new features. Unlike Symfony CakePHP team believes in doing everything them self. It is quite popular and got quite a big community support. Project is under active development.
Compatibility: PHP 4 / 5
Prado: Prado is actually component-based and event-driven programming framework for developing Web applications in PHP 5. PRADO stands for PHP Rapid Application Development Object-oriented. It's current version is 3.1.1 and development activity seems to be little slower then previous two. It is actually Microsoft ASP.NET framework ported on PHP. I think it is great work by Prado Team to come up with such a framework in PHP. It depends on one's programming style that whether they will like it or not. I am not biased but I believe I would use original ASP.NET rather then it's clone in PHP. I appreciate Prado Teams efforts and it would really help who is migrating to PHP from ASP platform or want to migrate from PHP to ASP platform.
CodeIgniter: Another PHP Framework based on MVC architecture and it is easy to start with. It is easier for someone who is just starting with MVC and PHP. It's got good Documentation and quite comprehensive User Guide. It supports PHP 4 and PHP 5 both. Currently 1.6.1 is stable version. More or less like CakePHP and have it's own ORM module. CodeIgniter could be used in small to mid-sized PHP projects and your shared hosting server won't hurt with it.
Kohana: It's CodeIgniter brother, I mean based on CI. When CodeIgniter guys were giving more concentration on professional projects and request of CI users been pending then some of the community members started a new project and named Kohana. Kohana is strict PHP 5 framework. It comes with all the good features of CI and addes up where CI lacked or whatever was missing. It is quite appealing to me but documentation wise this project is behind CI.
Zend Framework: Zend The PHP Company..! The framework from Zend itself which is open source. It is quite loosely coupled and framework don't force you to follow any coding standards. You can continue with your own convention and still use Zend. Even using full framework is not required. One can pull useful class library from Zend Framework and use them in their own way. But somehow Zend is not able to attract mass with this framework. Zend tried to do everything from scratch for this framework although Pear has got really good class libraries which can be used to build on. Yes If you need to consume web-services it's got lot of stuff for you almost all famous web-services has been taken into consideration and specific classes to them has been developed so that you can consume it easily. Current stable version is 1.5 and it has got good documentation too. New Zend website is built on Zend Framework 1.5 and it supports PHP5 only.
Agavi: One more PHP 5 Framework which seems to be quite powerful and unique. I would like to paste their preface paragraph here to let you know more about it.
"Agavi is a Web Application Framework for PHP 5. While it lies in the nature of a framework to simplify the application development process, Agavi won't do that at any cost. The primary goals are flexibility, cleanliness and structure. You won't find HTML Form helper methods in Agavi (because they aren't necessary, we have something better, more on that later), and we use XML configuration files because we believe that they offer better structuring abilites than alternatives such as YAML. If you're looking for a solution that assists you in serious high-end development, that has smart and innovative solutions to common problems that haven't been solved properly before, and that encourages and enforces a clean development process to ensure your code remains maintainable and extensible, you've come to the right place."
Documentation and API Guide seems to be good but it's not for small projects and development seems to be quite slow. As current stable version is 0.11 which is same since quite a long time I believe it's difficult to advice someone to use in practical projects.

There are other frameworks too which I didn't talked about in my this blog post due to one reason or another to name few of them they are eZ Components, PHP on TRAX, Seagull, WACT, WASP, ZooP, Akelos, Fusebox and qcodo.

Let's make the web faster

PHP performance tips

Author: Eric Higgins, Google Webmaster
Recommended experience: Beginner to intermediate PHP knowledge
PHP is a very popular scripting language, used on many popular sites across the web. In this article, we hope to help you to improve the performance of your PHP scripts with some changes that you can make very quickly and painlessly. Please keep in mind that your own performance gains may vary greatly, depending on which version of PHP you are running, your web server environment, and the complexity of your code.

Profile your code to pinpoint bottlenecks

Hoare's dictum states that Premature optimization is the root of all evil, an important thing to keep in mind when trying to make your web sites faster. Before changing your code, you'll need to determine what is causing it to be slow. You may go through this guide, and many others on optimizing PHP, when the issue might instead be database-related or network-related. By profiling your PHP code, you can try to pinpoint bottlenecks.

Upgrade your version of PHP

The team of developers who maintain the PHP engine have made a number of significant performance improvements over the years. If your web server is still running an older version, such as PHP 3 or PHP 4, you may want to investigate upgrading before you try to optimize your code.

Use caching

Making use of a caching module, such as Memcache, or a templating system which supports caching, such as Smarty, can help to improve the performance of your website by caching database results and rendered pages.

Use output buffering

PHP uses a memory buffer to store all of the data that your script tries to print. This buffer can make your pages seem slow, because your users have to wait for the buffer to fill up before it sends them any data. Fortunately, you can make some changes that will force PHP to flush the output buffers sooner, and more often, making your site feel faster to your users.

Avoid writing naive setters and getters

When writing classes in PHP, you can save time and speed up your scripts by working with object properties directly, rather than writing naive setters and getters. In the following example, the dog class uses the setName() and getName() methods for accessing the name property.
class dog {
  public $name = '';

  public function setName($name) {
    $this->name = $name;
  }

  public function getName() {
    return $this->name;
  }
}
Notice that setName() and getName() do nothing more than store and return the name property, respectively.
$rover = new dog();
$rover->setName('rover');
echo $rover->getName();
Setting and calling the name property directly can run up to 100% faster, as well as cutting down on development time.
$rover = new dog();
$rover->name = 'rover';
echo $rover->name;

Don't copy variables for no reason

Sometimes PHP novices attempt to make their code "cleaner" by copying predefined variables to variables with shorter names before working with them. What this actually results in is doubled memory consumption (when the variable is altered), and therefore, slow scripts. In the following example, if a user had inserted 512KB worth of characters into a textarea field. This implementation would result in nearly 1MB of memory being used.
$description = strip_tags($_POST['description']);
echo $description;
There's no reason to copy the variable above. You can simply do this operation inline and avoid the extra memory consumption:
echo strip_tags($_POST['description']);

Avoid doing SQL queries within a loop

A common mistake is placing a SQL query inside of a loop. This results in multiple round trips to the database, and significantly slower scripts. In the example below, you can change the loop to build a single SQL query and insert all of your users at once.
foreach ($userList as $user) {
  $query = 'INSERT INTO users (first_name,last_name) VALUES("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
  mysql_query($query);
  }
Produces:
INSERT INTO users (first_name,last_name) VALUES("John", "Doe")
Instead of using a loop, you can combine the data into a single database query.

$userData = array();
foreach ($userList as $user) {
    $userData[] = '("' . $user['first_name'] . '", "' . $user['last_name'] . '")';
 }
$query = 'INSERT INTO users (first_name,last_name) VALUES' . implode(',', $userData);
mysql_query($query);
Produces:
INSERT INTO users (first_name,last_name) VALUES("John", "Doe"),("Jane", "Doe")...

Additional resources