What is this all about..
Last time, I’ve introduced the Captain America of The PHP Ecosystem to you, aka Josh Lockhart, via a 7PHP ‘PHP Interview series to help drive thy PHP aspirations‘. This time we go a little bit further with Josh to find out ‘as much as we can‘ about his little masterpiece, I named Slim Framework – the PHP micro framework. Let’s get started..
And Now The Interview!
When did the project start? And the motivation behind?
The first commit to the Slim Framework GitHub repository was on September 20, 2010. But I had been working on the framework locally a few months before that.
I created Slim for myself to quickly build smaller client websites and web application APIs at New Media Campaigns. Many of my projects are APIs that manipulate and provide data to remote front-ends.
At that time, the popular frameworks were Symfony, Cake, CodeIgnitor, etc. But these were large, full-stack frameworks with a lot of overhead with regards to both LoC and to the time investment needed to learn them.
Rather than learn a larger framework, I wanted a small, nimble framework that focused more on the bare necessities: receiving an HTTP request, invoking the appropriate controller code, and returning an HTTP response. So I wrote Slim.
Is there any story behind you getting the simple name: Slim framework? (Because as goes the saying, simple is complex and not conceivable by everyone)
Not really. I wanted a name that 1) represented what I was building, and 2) wasn’t already taken! I did some research and settled on “Slim”.
What is Slim framework about and what does it try to solve?
As I mention on the Slim Framework website, Slim “is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.”
When Slim was first launched, the term “micro framework” did not have the mindshare it does now. Slim was a simple PHP framework that concentrated on the core necessities of a web application: receiving an HTTP request, dispatching the appropriate code, and returning an HTTP response.
Slim first and foremost solves this problem without requiring the developer to worry about the lower-level details of the HTTP protocol. The Slim Framework also provides additional features like middleware, helper methods for HTTP caching (and so on), and the ability to use custom views to render templates (e.g. with Twig or Smarty).
How do you define a PHP Micro framework and does Slim framework portray the exact meaning of it or even more?
I define “micro framework” as the simplest collection of tools necessary to receive an HTTP request, invoke the appropriate code, and return an HTTP response. The definition of “simple” is up for debate. Slim, for example, has zero third-party dependencies so its codebase (number of classes and LoC) is relatively small compared to other “micro frameworks” like Silex that rely on a more distributed component architecture on top of the larger Symfony codebase.
A “micro framework” also exemplifies simplicity with its underlying code. Slim’s codebase provides easy-to-read and easy-to-understand code. It avoids using syntactical shortcuts or magical architecture whereever possible. I want any PHP developer to be able to peek into the source code and be able to understand how Slim works.
How is Slim framework different from other frameworks like Laravel, Symfony or Zend
Laravel, Symfony, and Zend are all great products. But they are also very large full-stack frameworks that consist of many individual components that work together to perform many different tasks needed by large and complex web applications.
They come with a lot of overhead (number of classes, LoC, architectural complexity, learning curves, etc.).
Slim, on the other hand, is itself a single component library that answers the core need of any web application: receiving an HTTP request, routing the request to the appropriate code, and returning an HTTP response (much like I’ve described in previous answers above). It has minimal overhead and is super easy to pick up and use immediately.
Is Slim framework similar to symfony’s Silex? How do they differ?
Slim is both similar to and different from Silex. Slim is a single component library whereas Silex is a collection of components derived from the larger Symfony codebase.
Silex requires a more thorough understanding of Symfony components and how they work together. I’m not saying one is any better or worse than the other… they differ based on their architecture.
However, both Slim and Silex solve the same fundamental problem which is to build a web application with the simplest tools necessary to receive an HTTP request and deliver an HTTP response.
Would you say that Slim framework is better than Silex?
Of course! haha. But I’m a bit biased 🙂 Use the right tool for the job.
What has prompted you to start Slim framework and not using an existing framework
When I began writing the Slim Framework, there wasn’t anything that fit my need. A vast majority of the existing frameworks were larger, full-stack frameworks and I was looking for something far simpler.
Slim was also my opportunity to improve my skills as a web application developer. At the time, I was not that familiar with the HTTP protocol. Slim gave me a great opportunity to learn more about the HTTP protocol as I built out the framework.
Why should someone choose Slim framework instead of, let’s say, symfony or zend framework or Laravel – How would you convince them to use it
I’d say the Slim Framework has minimal overhead, is super easy use, and it has fantastic documentation should you need it. You can install it and have a “Hello World” script running in under 5 minutes.
Can Slim framework be used for ANY kind of application of any level? (from small to enterprise apps?)
Yes, I believe Slim can be used to build any application. It can be the only tool or one of many tools used to build the application. In some cases though, there may be other tools more appropriate. So use the tool that best solves the problem described in the project specs.
According to you where does Slim frameworks fall short?
I’d say that Slim may not be appropriate for applications that would be better served by an “all-in-one” framework like Laravel or Symfony. Both Laravel and Symfony provide a tight-knit set of tools that work well together to build larger and more complex applications.
In which case, Slim is probably not the best tool for the job. But for a vast majority of smaller applications and APIs, Slim will 100% fit the bill.
Are you satisfied with the way things are taking shape with this project?
Absolutely! I had no idea that Slim would become as successful as it has. Slim has recently crossed 3000 stars on GitHub, and is (I believe) the 13th most starred PHP repository on GitHub.
I’m even more satisfied with the supportive community that has grown around Slim. The support forums are full of nice and helpful users ready and willing to help each other. There are also many collaborators and contributors who have helped Slim become even better. And for that I am super thankful!
If you had to re-do it all over again, what are would you do different?
Slim Framework version 1.0 (way back in 2010) was built as a large singleton. Obviously, I would not do that if I were to start over 🙂 But you live and learn!
How is the actual team inside Slim framework structured? (Or is it currently a one-man show?)
Slim began as a one-man show, but there is now a dedicated working group with about 4-5 developers who are contributing to Slim on a daily basis. There are also at least 50 contributors who have helped on GitHub.
Is Slim framework backed by any commercial entity? (I mean for example, Symfony Labs is behind Symfony, Zend Inc is behind ZF..etc)
Yes! New Media Campaigns has sponsored the Slim Framework since the very beginning. The fine folks at New Media Campaigns have been super helpful fostering Slim’s development so that it can become even better.
New Media Campaigns also provides design, development, and marketing services to clients large and small who need websites and web applications, perhaps built with the Slim Framework!
Is this project 100% from free motivation, or somehow you generate some revenue to compensate for all the hard work behind?
I do not get paid a salary to work on Slim. I do accept donations, though. Donations are a great way to say thanks for my open source work. Donations will help validate my time spent on the framework and perhaps buy me a coffee or two 🙂
The good moments of your journey so far and any bad moments of it?
Good moments: seeing the great community build up around the framework.
Bad moments: Learning how to say “no” to a lot of decent ideas to avoid scope creep and feature bloat.
Are you against a full-stack framework?
Nope. If a full-stack framework is the best tool for the job at hand, by all means use it!
Which one is your favorite among Laravel, Symfony, Zend..etc?
Probably Laravel, but I’ve heard tons a great things about both Symfony and Zend.
I hear that slim framework version 3 will be out soon – tell us a bit about: when it will be out, what will be about, the new features and all..
Version 3 should be available in early 2014. Progress is coming along very quickly, and there’s a lot of cool new features coming! Version 3 is all about simplification and refactoring.
There’s been a lot of baggage and backwards-compatibility that I’ve been carrying up to now; version 3 will shed this baggage and provide a simpler, optimized codebase for Slim’s future. As for features:
- Improved dependency injection and service location with Pimple
- Better cryptography
- First-class session support
- Improved decoupling with interfaces
- Initiate downloads from the filesystem or shell process output
More details coming soon!
Will you still give support to version 2 or will you urge everyone to move upwards? And on the compatibility levels, how is it gonna be?
I always encourage everyone to move upwards. But version 2 users will always find support on the Slim Framework support forums. I will make sure version 2 documentation is archived and made available for download, too.
As for backwards compatibility, version 3 will be a fresh start with lots of refactoring. So, yes, there will definitely be a few changes.
What are your future plans with Slim framework?
My plans right now are to continue molding Slim into the perfect PHP micro framework. There is a growing community, too. So who knows. Is there a “Slim Con” in the future? We’ll see!
Is it being used by a wide audience, would you have any metrics for it?
Slim has been very well received! It has over 3000 stars on GitHub. Over 85,070 people have installed Slim via Composer so far.
Something I heard people say online: “slim lacks certain attentions in terms of documentation and guides. There is still no great tutorial for it..” What is your call on this?
I’ve heard this, and I intend to answer this with the version 3.0 release. The current documentation is very good, in my opinion. But I agree, there is a lack of tutorials to help beginners learn how Slim can help them.
“Slim favors cleanliness over terseness and common cases over edge cases” For those that might find this an ambiguous statement, could please explain a bit what is meant by “terseness” and “edge cases” in this case? And how Slim is solving these ambiguities?
I need to reword that 🙂 What I mean is that Slim does not try to be concise and terse when lengthier, simpler, and more obvious code will achieve the same goal.
I want Slim’s source code to be super easy to read so that beginners can learn from the code to become better programmers.
As far as building up a framework, could you share how to approach this kind of development – what does a PHP programmer need to invest time in, what he needs to learn and be equipped with to be able to conceive a framework.
Don’t invest too much time learning PHP. Instead, learn the HTTP protocol, how to read raw HTTP requests and build raw HTTP responses. These skills will translate across programming languages and will always be useful.
Building a framework entails a lot of decision at different level also, could you share what are some of those decisions and the factors affecting those decisions
The most important decisions I’ve made building the Slim Framework is how much to build into the framework itself and how much to leave to the individual application developer.
Like I mentioned in an earlier question, learning to say “no” to a lot of decent ideas has been the hardest lesson I’ve learned. My primary focus has been to improve Slim while keeping it small and focused.
In my opinion, the best micro framework will help the developer when needed but otherwise stay out of the developer’s way.
How do you see the framework ecosystem in the next few years coming?
I think the future is already here! I’ve noticed a major shift from monolithic frameworks to more componentized architecture, mainly thanks to Composer and Packagist.
It’s so easy to grocery shop for components needed to build out any application. For example, I can use Slim, Eloquent ORM, and Monolog to build out a basic web application with HTTP request routing, a database backend, and powerful logging. I can mix and match any number of thousands of available PHP packages to build whatever I can dream of.
I think the future will further refine this development model.
A PHP framework creator that you admire?
Fabien Potencier. He’s an amazing developer and has been an inspiration of mine for quite some time. I’ve learned a lot by reading his blog and reviewing his code.
Would you have the names of some prominent projects that are using Slim?
There are many others, but these are the first that come to mind.
One slim-based project that you find is making effective use of Slim’s philosophy and good coding principles that people can learn from?
Statamic is a great example. They have built a wonderful, flat-file content management system on top of Slim. The entire project, including its design, user interface, and data architecture all epitomize Slim’s core philosophies of simplicity.
Could you tell us what are some of the best practices you believe in and would strongly preach to anyone
Build, test, and deploy often. Iterate quickly. Do not wait forever to release a polished product because the odds are your product will never see the light of day.
Build a good product, release it, and grow your customer base. Then iterate, iterate, iterate!
If Anyone needs help concerning Slim framework, where can they get help or hang out?
Go to http://help.slimframework.com
If someone wants to code efficiently & comfortably with Slim framework, what is your advice?
Read and adhere to the best-practices put forward by PHP The Right Way. And use Composer.
For those who want to donate to support this project, what are the options available?
You can donate weekly with GitTip, or you can send a one-time donation with credit card by clicking on the “Donate” button on Slim’s website home page:
The web presence of Slim framework?
If someone wants to be able to understand HTTP protocol, the
way you perfectly do as you demonstrated with Slim, what is your advice?
Any recommended resource/books?
I’m by no means an expert at the HTTP protocol 🙂 I’m still learning.
But I do recommend these resources:
- http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
- http://www.amazon.com/HTTP-The-Definitive-Guide-Guides/dp/1565925092/
- http://net.tutsplus.com/tutorials/tools-and-tips/http-the-protocol-every-web-developer-must-know-part-1/
- http://www.w3.org/Protocols/rfc2616/rfc2616.html
- http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding
How would you define a middleware
Middleware is a terrible term, but it has become the defacto label that describes a code layer that exists between the raw HTTP request and the
core application, and between the core application and the raw HTTP response. This applies to a myriad of frameworks and languages. With Slim, middleware is a PHP class that extends the \Slim\Middleware abstract class.
Middleware classes are run around the core Slim application (an instance of \Slim\Slim). You can wrap multiple middleware layers around the Slim application, treating it like an onion.
The HTTP request will work its way down through each middleware layer until it reaches the core Slim application, and then the HTTP response will work its way out from the Slim application through each middleware layer until it is delivered to the HTTP client.
Admittedly, it takes time to understand exactly how this works, but it provides enormous flexibility and the ability to manipulate the raw HTTP request and response objects before and after the Slim application is run.
Is middleware really needed when event handlers are there
– (this question was contributed by Hari KT via twitter)
That’s a good question. And the honest answer is no. Slim has been, is, and probably always will be a project that I build for myself. It is a playground that I use to experiment and learn new things about HTTP and application architecture.
Middleware and event hooks are two different means to the same goal. Use one, use both. It’s up to you. But both have been actively adopted by Slim Framework users so I won’t be removing one or the other anytime soon.
What’s Next?
Now that you’ve got a comprehensive ‘apercu’ of Slim, you can probably read a bit more from someone (another PHP community friend – Jeremy Kendall ) who has actually used it in one of his open-source projects.
Besides, he has also given a couple of nice conference talk about Slim, so this is surely a-must-read to satiate your ‘php/slim awareness’:- Slim PHP Micro Framework Through The Lens Of Jeremy Kendall.
A quick correction: Sensio Labs is the company behind Symfony.