36

I would like to try Silex but i've some questions.

I know to use Symfony2 and i would like to know if Silex is very different of Symfony or it's the same thing (same operation, same code... ) ?

Moreover, Silex is recommanded for small PHP projects and Symfony for medium or big projects , it's true ?

j0k
  • 22,600
  • 28
  • 79
  • 90
Alex L.
  • 813
  • 2
  • 17
  • 34

8 Answers8

46

A few things worth noting:

  • Silex is based on the Symfony2 components, just like the Symfony2 framework is. As such, it can be considered an alternative user interface to the components (the user being a web developer).
  • Since they use the same basis, migration between them should be relatively easy.
  • Just like Symfony2, Silex is mostly a controller framework. It provides you with some structure, but the model and view parts are handled by third-party libraries (such as Twig or Doctrine).
  • Since your business logic should not be in your controllers anyway, if you separate that code out and keep your controllers light, the limiting factor in terms of project size will only be the amount of routes you have.

That said, Silex will not give you the bundles that Symfony2 has.

igorw
  • 27,759
  • 5
  • 78
  • 90
  • 7
    Migration between the two is far from easy (going Sy2 -> Silex) especially considering the extreme lack of good, complete documentation for the Silex providers to Symfony components. That being said, your other points are right on the money. The other major difference is that Symfony2 is production ready and Silex is still in -dev mode. – lucian303 Oct 15 '12 at 22:57
  • 2
    Symfony => Silex will be harder than vice versa because the things you took for granted are now no longer there. The core providers in silex have decent documentation, but most third-party providers do not. – igorw Oct 15 '12 at 23:14
  • igorw I'm a bit confused by what you mean by "your business logic shouldn't be in your controllers anyway" because if it doesn't go in your controllers, where does it go then? Does it go in the entities? or do you put it in services? – ILikeTacos Oct 02 '13 at 14:49
  • 2
    @AlanChavez yes, entities, services, value objects. that's where the business logic lies. not in something framework specific like a controller. – igorw Oct 02 '13 at 23:51
  • @igorw interesting... A few months ago I "inherited" a symfony project and the controllers are nowhere near "light". Most of the business logic is in there, and I thought that was the way it was supposed to work. – ILikeTacos Oct 03 '13 at 02:15
  • 1
    Controllers tend to be abused and end up doing a lot they shouldn't. The controller's responsibility should limit to be a mediator between the http world (requests, responses), your views (html, json) and your business logic. In other words, if you have http or html stuff mixed with your business logic, you are doing it wrong. So if you have a "shipOrder" method for business logic, there shouldn't be any html or http stuff inside that method. You would only have a thin controller wrapping it to handle http requests and passing results to a view renderer. – Jens Apr 13 '14 at 16:29
15

Here are some interesting thoughts on when to use Silex (especially in the comments): https://web.archive.org/web/20160131151109/http://www.testically.org/2011/10/11/is-there-a-specific-situation-when-to-use-a-php-micro-framework-like-silex/

Silex itself is pretty bare, which means that if you want more then just routing and tests you will need to add specific features (DB, Twig ...) in form of Services. I recommend to take a look at some readymade Plates that provide you with this: https://github.com/lyrixx/Silex-Kitchen-Edition or https://github.com/ivoba/superleansilexplate (thats mine :))

Another point is that Silex has a probably lighter footprint than Symfony2, so if you need a smaller & faster site, Silex is worth a consideration.

Weston Wedding
  • 136
  • 1
  • 8
ivoba
  • 5,780
  • 5
  • 48
  • 55
8

(UPDATE) Since Symfony 2.8 You can use symfony 2 as a microframework with a micro kernel controller. See short description here: symfony.com/blog/new-in-symfony-2-8-symfony-as-a-microframework. Now Symfony gives us more control over the structure and architecture. Good alternative to Silex if You prefer the Symfony 2 style.

Comparing Silex to Symfony before 2.8 release

Silex microframework is based on Symfony but it's not exactly the same thing. Using a full-stack framework such as Symfony for a small project is simply overkilling the project.

In a microframework, you have more flexibility to choose the tools you want to use. You can make more decisions about application architecture and logic. In a full-stack framework with some extend you would have an architecture and a logic already predefined with restrictions and limitations to its configuration.

Silex was designed to build up the tool rather than get the set tools that you might not need. I would say that for small projects in Symfony you would have to remove features - were in Silex you would have to add them.

It is also not true that Silex isn't fit for larger projects. Silex can be used with success for larger projects but remember that you would have to build up your tools to fit your requirements (if you need to customize the architecture and logic - perhaps this is the right way to go). Other than that, I would consider using Symfony instead, because Symfony already has bunch of tools available out of the box.

Silex dependency injection

Bear in mind that: Silex limitations

To conclude, Silex is good for smaller applications and for those, it can surely replace Symfony. Silex can also be used for larger projects (but for larger applications I would recommend to use full-stack framework instead, like Symfony).

Reference for slides at: http://www.slideshare.net/dustin.whittle/silex-from-micro-to-full-stack . If you feel like it, go ahead and read some more about the Silex framework.

I also recommend watching this intro comparing Silex to Symfony: https://www.youtube.com/watch?v=RDVtnsoOysE.

Again, a few Pro for using Silex coming from people who actually use it: https://www.youtube.com/watch?v=OJcdHGJFfLU

Antoine
  • 800
  • 3
  • 14
  • 29
DevWL
  • 17,345
  • 6
  • 90
  • 86
7

Silex is good for small projects, but it can be used for big projects as well. What I like the most of Silex is that I have complete control over my project structure but it's my responsibility if my project is well organized or not.
Also I recommend it over symfony if like me, you moved your application logic to the client side using a JS framework. For me it feels an overkill to use symfony only to serve a few json requests.

olanod
  • 30,306
  • 7
  • 46
  • 75
  • Hi olanod, although this post is quite old I would like to know which JS framework you used in conjunction with sylix? Thanks! – user2345998 Jul 09 '15 at 09:30
  • 1
    Hello, at that time I was using angular which is still very(the most?) popular. Now I'm an early adopter of 'aurelia', a cool next-gen framework which is very easy to use ;) – olanod Jul 09 '15 at 19:48
5

Silex is based on the independent Symfony2 components and isn't truly considered a full-stack web application framework like Symfony is. You should only use it for very small projects that only require a few files, or you'll outgrow it pretty quickly.

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
  • 7
    using Silex for small projects only? Doh. You can use it in your big project too. Why not? You can create your own structure of the application - moving business logic out of controllers, you can create repositories (Doctrine DBAL or PDO). – Andrzej Ośmiałowski Aug 07 '13 at 12:52
1

Silex is a great framework for small as well as big applications. Giving structure to the project is your responsibility in Silex. As the project becomes larger, you can nicely integrate symfony components into it although the documentation for the symfony provider is not so good especially for symfony security component.

Silex is great for prototyping projects. If you know you will be using most of the symfony components then go for symfony because you will end up with integrating almost all symfony components into silex.

In my case I needed speed right out of the box and silex provided me with the speed and although I am using most of the symfony components, it is a lot faster than symfony out of the box.

sonam
  • 3,720
  • 12
  • 45
  • 66
1

At the moment I write this, Silex is in maintenance mode and it's end of life occured in June 2018.

Which means you shouldn't use it anymore for new projects.

They recommend you to use Symfony 4 instead.

Silex was really good and fast (maybe faster than symfony 4 for simple requests/requirements), but SF4 may bring some new stack and benefits to our applications.

Update: However, in all of my attempts on migrating from Silex to Symfony 4, the simple services took 4x times more to respond no matter what I do. Silex seems to do a much better job for simple micro services.

Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59
-2

Silex is a PHP microframework. It is use for the small project.The coding style of the symfony and the silex is almost similar to the symfony.But the symfony is use for the large projects

user2779489
  • 391
  • 1
  • 3
  • 11
  • The size doesn't matter. Symfony has a more rigid structure, which can be handy if you work with many developers on the project. Whereas in Silex you are more responsible for the structure. For me Silex is less obfusticating and more close to PHP and I work alone, so that's what I use, even on a big project. – martti Oct 11 '17 at 10:50