DEV Community

Discussion on: Decision Time: PHP Framework Dilemma

Collapse
 
leob profile image
leob • Edited

I'm (actually) a fan of Rails, so if I translate that to the PHP world then that would be Laravel, which is indeed what I tend to use when I need to use PHP. However, I'm mostly building "applications" meaning that I definitely benefit from what Rails or Laravel have to offer.

Now, first thing that came to my mind as a was reading your post is "Laravel is probably overkill for 90% of the author's projects". But then at the end of your post I was reading "Ok to have one option for small stuff and one for big projects". So that made me think "Laravel" again.

(or did you actually mean two different options, one for small site and one for bigger sites?
In that case, for the small/simple website - why not forego PHP completely and go with a static site generator, Gatsby or Jekyll or Nextjs or whatever, and Github pages or Netlify instead?)

Anyway ... do most of your projects (even the simple ones) use a database (and for instance login)? If so then I'd say don't worry about 'Laravel is overkill'. If you have php 7.2 or higher installed, and you type this in your terminal:

composer create-project --prefer-dist laravel/laravel blog

then 30 seconds later you'll have created a simple and lightweight website called "blog". Next run the following command:

php artisan serve

and you can view your site in the browser, a simple page with some links (instead of php artisan serve you can of course just use Apache or Nginx instead).

Now, the app as just generated comes with authentication and database connectivity, however if you view your newly generated app (see above), then it will actually not hit the database or show a login screen. So it just works without a database, until you try to activate the authentication functionality.

As for the size of the generated app, most of it is in the "vendor" directory which is around 62MB. However, in production you can cut this in half (32MB) by running:

composer install --no-dev --optimize-autoloader

So that's going down to 32MB on the server (most of which would not be loaded or executed at all, and none of which would be downloaded by a user) - not a lot of overhead for your 'simple' site, and the good thing is that:

  • if ever your simple site needs to grow and become more complicated, Laravel has you covered, and for the smaller site it arguably doesn't get in your way

  • you get to utilize your Laravel experience for both the smaller and the bigger projects - call it leverage

One critical note:

I was referring to Ruby on Rails in the beginning. While it's undeniable that Laravel was inspired by Rails, I always get the feeling that Rails keeps it just a bit more simple and lightweight (call it elegant).

When I write Rails code I can do it pretty intuitively, with Laravel however I more often wonder "isn't this more complicated than it needs to be". But maybe that's just me, or it's the syntax of PHP which is more convoluted than Ruby.

By the way, I don't have experience with Symfony. I've read articles explaining that Symfony promotes "better architecture" than Laravel, however I believe Laravel is a bit simpler and easier to get stuff done. Symfony might be beneficial when you need to build really big and complex stuff.