How to choose a PHP framework


[ad_1]

PHP is one of the most popular programming languages around the world, and the recent PHP 7 release made this server-side programming language better and more stable than ever.

PHP is widely used in major projects. Facebook, for example, utilizes PHP for maintaining and creating their internal systems. WordPress uses PHP to power its internals, which in return is powering more than 26% of the web. Currently, PHP powers more than 82% of websites (whose server-side programming languages the Web Technology Surveys site is able to track).

In this article, we’ll look at three of the most popular PHP frameworks: Symfony, Laravel, and Yii. We’ll examine how they compare to help you decide which one might be the best fit for your needs.

Why pick a PHP framework?

What’s the point of using a framework instead of raw PHP to develop your application? A few benefits of using a framework include:

  • A PHP framework makes development faster. For example, you don’t have to write complex queries to retrieve the data from the database. PHP frameworks provide CRUD operations (Create, Read, Update, and Delete).
  • Frameworks enable developers to scale systems easily.
  • Code maintenance is easier than with a vanilla PHP application. The application code is concise and easy to work with.
  • The MVC model ensures rapid development.
  • Frameworks are better in securing the web application from common security threats.
  • The don’t repeat yourself (DRY) principle ensures that minimal code has maximum impact.

The above benefits are too significant to be ignored. Even though raw PHP can be used to create any application, the current development standards require tools and time-management skills to meet the market demand.

How to choose a PHP framework

Answering a few questions can help you choose a framework:

  1. What are the features and functionality of the framework? (Does it offer what I need?)
  2. What is the learning curve of the framework?
  3. How scalable is the framework?
  4. Is the framework actively developed and maintained by the core team?
  5. Does the framework provide long-term support (LTS support) ?
  6. Does the framework have a strong community support?

Symfony, Laravel, and Yii

Before diving into technical specifics, here’s an overview of the contenders:

Symfony

Symfony is a set of reusable PHP components, enabling the developer to create scalable, high-performance applications. With 30 components from which to choose, the developer has the complete freedom to experiment and work in a RAD environment. Symfony APIs also enable easy integration with third-party applications, and it can be used with popular front-end frameworks, such as AngularJS.

Many popular projects, including Drupal and phpBB, also use a Symfony framework. In fact, Laravel, the most popular PHP framework, is build off of Symfony.

Laravel

Laravel, which is known as the “PHP framework for Web Artisans,” offers an excellent community and wins as the most popular framework. (One of the leading Laravel developers on Livecoding.tv is Sfiskell.)

In May 2015 Laravel announced that version 5.1 will offer long-term support for two years. Version 5.2 rolled out in December 2015. Many hosting companies provide Laravel support and offer hosting solutions for Laravel applications. Check out the Built with Laravel site to see great example projects.

Yii

Created by Qiang Xue in 2008, Yii is a secure, fast, high-performance application/web-development framework. Yii utilizes the Composer dependency manager for PHP for handling different dependencies and installations (more on it later). Yii also is the fastest PHP framework, thanks to the lazy loading technique.

Another great feature of Yii is jQuery integration. The integration enables front-end developers to embrace the framework quickly, and it uses scaffolding to generate code. Similar to Symfony, Yii also utilizes components to enable rapid application development.

How they compare

All three frameworks are great for building Web 2.0 applications, but each framework serves a different purpose. Let’s look at their features and how they stack up.

Templating engines

Templating engines minimize developer effort and provides better functionality in writing front-end code. Templating engines provide features such as automatic HTML escaping and filters, and fill the gap left by raw PHP.

Symfony Twig template system

Twig is a modern templating system for PHP. Symfony utilizes Twig to its advantage and enables developers to write clean, concise code and the ability to do more than with raw PHP. For example, it takes the following verbose code to write escaping:

<?php echo $var ?> <?php echo htmlspecialchars($var, ENT_QUOTES, 'UTF-8') ?>

Twig does the same with the following code:

{{ var }} {{ var|escape }} {{ var|e }} {# shortcut to escape a variable #}

See the Twig site to learn more about its features.

Laravel Blade templating system

Unlike other templating systems, Blade lets you use PHP code in the views. Also, Blade has zero overhead to application performance because the blade view files are stored in .blade.php extension. All the code in the view files is converted into raw PHP during processing.

Yii Default templating system

Yii doesn’t utilize any third party templating system by default, but that doesn’t mean it lacks templating system support. The choice of the templating system depends on the development team. Twig and Smarty are recommended. Symfony uses Twig, so if you have used Symfony in past, you might want to utilize Twig for your next Yii project.

There is no clear winner here. All three frameworks use templating engines for better front-end coding and maintenance. A small advantage to Yii is that the framework does not have a pre-defined templating system.

Framework differences

Every framework is created differently. Symfony works on reusable components and provides the best modularity. Symfony also utilizes the model and controller for developing a web application, which may look rusty for many new developers, but it works. Also, Symfony is a good example of the modular framework. You can use the 30 components provided by Symfony in your project in a modular fashion.

Yii uses an MVC framework. (Symfony does provide support for MVC, which is discussed in more detail in Is Symfony2 a MVC framework on the blog.sznapka.pl site.)

Symfony can be used for rapid development and complex projects. Even though there is a debate on which framework is better for complex projects, Symfony does showcase brilliant complexity handling compared to other frameworks. Yii also utilizes components, but is not as modular as Symfony. Laravel doesn’t provide a modular approach as sharp as the other two frameworks.

If you are looking for a modular framework, go for Symfony. Otherwise, Laravel and Yii are both great choices.

Installation

The three frameworks provide multiple installation procedures. If you are using Composer for handling packages, you will be happy to know that all the frameworks can be installed via Composer.

For Symfony, the role of the Composer is more crucial. The idea of component handling is best done by using the Composer PHP dependency manager.

There are other ways of installing the respective frameworks. For example, you can install the frameworks using simple archive method.

After installation, Yii provides you with a web app and a basic template to work on. Symfony 2 also provides a demo app to get started.

Laravel is also easy to install using Composer create-project or via Laravel Installer. Check out the Laravel installation guide for details.

Rapid development

From the perspective of the company or the client, quickly getting the application to the market to meet consumer demand and beat competitors is important. Symfony stands out for being a robust framework with a strong community standing behind it. Laravel is growing rapidly, but still has a way to go before being considered the de facto choice for PHP development. On the other hand, if you have no knowledge of any PHP frameworks and want to get started as quickly as possible, consider Laravel. Laravel has an easy learning curve, and you’ll find lots of tutorials online to help get you started. Yii takes performance to the next level, and provides code scaffolding for faster code generation and development.

Performance

The performance of any application only matters if it is a real-time application using critical data. How many web-based applications depend on high performance? Not many, but the performance of frameworks can play a crucial role in many projects.

Social networks are prime example of real-time events and one of our star streamers, jadson, built a mobile social network using Yii2. When it comes to choosing the best framework for coding a high-performance application, Yii stands out as the fastest PHP framework in our lot.

Laravel performance is highly debatable. It is slowest, but does that matter? You’ll find online resources for speeding up performance, including a guide on GitHub for making your Laravel application faster.

Database support

Symfony 2 offers better database support. You can work with an array of databases, including NoSQL and DynamoDB. Yii and Laravel are also useful in this regard, but they support fewer databases than Symfony. The database supported by each framework is shown in Table 1.

Table 1
Framework Laravel Yii Symfony 2
 Database

SQLite
MySQL
PostgreSQL
Redis
Microsoft BI
MongoDB

MySQL
SQLite
Microsoft BI
Oracle
PostgreSQL
MongoDB

Microsoft BI
MongoDB
MySQL
NoSQL
PostgreSQL
CouchDB
DynamoDB
GemFire
GraphDB
MemBase
MemCacheDB
Oracle
Apache Jackrabbit

Community and resources

A big predictor for an open source framework’s longevity is the strength of its community. All the three frameworks have solid communities, although Symfony’s might be a bit more mature. Communities evolve, so predicting the dynamics of the communities in the future is challenging.

When it comes to learning material and documentation, Laravel stands out, although Symfony and Yii aren’t lagging far behind:

Extendability

Frameworks are structures that can be extended with extensions or packages, improving their functionality and scope. When it comes to extensions, Laravel is the winner. Packalyst, a directory of Laravel packages, offers more than 9,000 packages. Yii and Symfony, on the other hand, offer around 2800 extensions and 2830 bundles, respectively. With three times the number of extensions, Laravel seems to be the best framework in this regard.

Similarities

We have looked at the differences between the frameworks. Now let’s look at their similarities:

  • All three frameworks are full-stack PHP frameworks and offer the functionalities for creating web application, from front-end code writing to back-end data retrieval.
  • The projects are open source and their source code can be found on GitHub, making it easy for anyone to contribute:
  • The frameworks are well documented and supported by a large communities.
  • They each support ORM (Object Relationship Mapping). ORM is highly favored for writing OO code for your application.
  • They are robust, secure, and reliable for creating Web 2.0 applications.

Still stuck? Maybe these checklists will help you narrow down an option:

Symfony:

  • offers an LTS release,
  • comes with loads of features,
  • is currently the most stable framework,
  • is a component-based framework and offers extensive modularity,
  • and has a great community with lots of learning resources.

Yii:

  • comes with Ajax support,
  • is great for developing real-time applications as it offers faster operations,
  • is highly extensible.
  • error handling is spot on,
  • is good for creating Restful Web Services,
  • and has a great community with lots of learning resources.

Laravel:

  • is the most popular framework in 2015-2016,
  • supports Composer for package management,
  • does unit testing well,
  • offers tons of packages for extending framework functionality,
  • and has a great community with lots of learning resources.

Conclusion

In the battle of Symfony vs. Laravel vs. Yii, all three PHP frameworks are excellent options that provide a full-stack development environment for developers. For me, Laravel is a winner that is emerging as a star with no sign of stopping.

Still, Symfony and Yii are both excellent frameworks. Symfony is well-established and with a bigger, more mature community. Yii is a unique framework that is robust, secure, and gets the job done.

To see the frameworks in action, check out what developers are using them for on Livecoding.tv, which has channels for Symfony, Yii, and Laravel. The developers are also available on chat or Skype during streaming sessions. Follow the developers, ask them your questions, and get answers in real-time.

Additional resources

[ad_2]

Source link

,

Leave a Reply