How I chose a lightweight PHP framework

Frameworks
To begin with, I’ll say that I’m a very big fan of something to patch and twitch, even if there is no special need for this. And recently, considering the XCache statistics on my server, I thought that I could optimize the amount of memory that it spends on opcache files of various frameworks. It is simple to do this - to rewrite everything using only one, the files of which would be common to all sites, which I have about 20, but for the most part they are quite simple and it would not have provided me with any particular difficulty to rewrite them. And then I started searching for the very framework, which ideally would have enough features to make development simple, and at the same time easy and fast. Here are the ones that I liked and my thoughts about them.

Phalcon

Phalcon
Interesting primarily because it is written in Cand compiles as a module for PHP. Judging by the benchmarks, it works much faster than others (somewhere 3 times faster than the average) and at the same time observing the rather familiar MVC structure. I was also very pleased that Phalcon uses Dependency Injection and provides its DI container, but judging by the tutorials, classes are often used directly, including static methods, which I personally try to avoid. By the way, I must say that the module compiled and earned the first time, without dancing with tambourines, which is always nice. After looking a little deeper, I began to see more flaws, firstly there are not many PHP programmers who know C well enough to help in its development, as a result Phalcon will develop more slowly than its PHP counterparts. Secondly, it invented a lot of its crutches, such as PHQL (Phalcon Query Language) to replace SQL, etc. As a result, we have a rather bold project with an unknown future.

Phpixie

Phpixie
I heard about it recently, it was mentioned in my tweet by Phil Sturgeon (PyroCMS developer and member of PHP-FIG) and at first I thought that it was just a joke. Seriously, I believe that not a single PHP programmer can listen to the intro on the main page until the end without laughing. The philosophy of PHPixie is that the framework should be quick and easy like a little fairy, this developers are trying to achieve an approach known pythonists as "Simple things should be simple, hard things should be possible." That is, the components of PHPixie are written so that in the simplest and fastest way they can cope with 90% of the routine tasks in developing sites, and the remaining 10% of the more rare tasks are supposed to be solved by the developer himself and there is no need to include them in the framework itself. I must say that none of my sites used anything that would not have happened in PHPixie, and even Dependency Injection is pretty good with them, although it tends to the Service Locator. Unlike other DI container implementations, new elements are added to it by extending the class, which is less flexible, but much more transparent, this allows you to completely avoid the procedural code and get recognition of the class of container elements in the IDE. Of the minuses, I can only note that it is quite difficult to take it seriously, and it is unlikely that you can convince your employees in the office to write anything on a framework with fairies and ponies.

Fat-free

image
The whole framework in one file! A huge plus immediately on the face: one file from the disk will load faster than many, and the size of this file is about 50 kilobytes. However, as it turned out, this whole file is far from the whole framework, but only its most basic part, that is, if you need access to the database, for example, classes will still have to be loaded. Moreover, the same XCache caches PHP code, in this case the gain from this approach, if it is, will be very small. Along with the framework, just a bunch of libraries are supplied, which is convenient if you do not use Composer and do not need to use it at all. It was also very surprising that their ORM does not support relationships between tables, without which it can be immediately thrown out the window, since this greatly reduces the scope of its use. This is actually the only framework I have reviewed

Silex , Slim and microframes.

image
A lot is known about these two. Since they both do not provide a full stack for development, everything will depend on which libraries you screw to them and how to do it. The flexibility of microframes comes from this, but on the other hand it will be more difficult to find a community and a support, since each programmer as a result has his own system. In addition, if the framework is written entirely by people alone it is much easier to master, since the code philosophy is similar. But if you have a Frankenstein assembled from different libraries that have a different style and approach, then it will be more difficult to figure it out. Ultimately, attempts to make Silex a complete e-framework with me lead to a collection of some kind of Symfony. It should be noted that writing code on Slim and Silex is intuitive, fast and without any magic.

Lithium

Lithium
There are a bit more innovations, for example, a single API for SQL and NoSQL databases, as well as a decentralized filter system, according to the developers. The framework was created by a former developer of CakePHP, and in places it is very noticeable, as for example when using models. Filters allow you to actually intercept a call to a class method and change its parameters and result on the fly. Flexible, but in the end you can get pasta code, similar to how plugins work in Wordpress. It is also surprising that such an innovative framework uses static methods so persistently. The simple architecture is good, that is, if you create a simple site, then the amount of code that you write is not much different from using Silex. In principle, it is very well suited for those who have worked with CakePHP in the past, but want to try something new.

So which one did I choose in the end? In the end, my choice was between Silex and PHPixie (yes, I was not afraid of fairies) and as a result, I still used both of them. Most of the sites were translated into Silex, and those that were written in Kohana were ported to PHPixie, whose interface is somewhat similar to it, especially the implementation of ORM. By doing this, I was able to reduce the amount of memory consumed by XCache by about 6 times, speed up page generation, and even managed to refactor a little along the way. In general, PHP is a country of a thousand frameworks, so I think everyone can find something to their liking.

Also popular now: