Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Comparing the PHP and Node.js ecosystems

Comparing the PHP and Node.js ecosystems

Over the last 5 years Lifely has changed it's tech stack a lot. Starting out with Symfony a couple of years ago, we moved to Node.js, then to Meteor (Javascript) and back to Node.js again (Typescript) while in the meantime also using Laravel for different PHP applications. In this talk we'll take a look at the differences between the PHP and Node.js ecosystems from a couple of different perspectives ranging from the languages themselves to their respective underlying infrastructure and what this all means for our devops- and development teams.

Bryan te Beek

October 19, 2018
Tweet

More Decks by Bryan te Beek

Other Decks in Programming

Transcript

  1. 1@bryantebeek Comparing the two Single-threaded (uses an event loop) Non-blocking,

    asynchronous I/O Bad on CPU intensive tasks (blocking) Runs on the performant and actively updated V8 engine (powers Chrome browser) Process exception, whole application restarts if not handled correctly 1. Architecture
  2. 1@bryantebeek Comparing the two Process pool (FPM) Synchronous I/O Execution

    failure / crash, much less of a problem Bootstraps whole application on each request (includes DB connection etc.) 1. Architecture
  3. 1@bryantebeek Comparing the two Both client and server are written

    in Javascript, easier to develop full stack (SPA) Need to wait for code to be build on file change No all-in-one frameworks that match the quality of their PHP counterparts Except for the big frameworks, there are a lot of small, actively updated packages 2. Development
  4. 1@bryantebeek Comparing the two A lot of great frameworks like

    Laravel and Symfony speed up development Easy local development environments (WAMP / LAMP / Laravel Homestead) Instant able to retest application on code change, no need to wait for builds There are a lot of packages that integrate directly with said frameworks, which make installation a breeze 2. Development
  5. 1@bryantebeek Comparing the two 2. Development Amount of packages from

    modulecounts.com PHP averages at 111/day, Node.js averages at 538/day
  6. 1@bryantebeek Comparing the two Less hosting solutions, needs more custom

    work to run it in production Requires building the code most of the time (Babel, Typescript) Need to watch the main process and make sure it keeps running at all times Docker helps, or other solutions like Systemd or Supervisor 3. DevOps
  7. 1@bryantebeek Comparing the two Countless of easy hosting solutions online

    Also means there is a lot of competition, drives down prices Extensions can be a bit of a problem (does your hosting support / include X?) Same holds for upgrading PHP versions 3. DevOps
  8. 1@bryantebeek Comparing the two Iterates really fast Javascript a few

    years ago was worse than PHP Evolved a lot with the recent ECMAScript editions Typescript saves the day. Write fully typed, highly maintainable code (generics, etc.) 4. Language
  9. 1@bryantebeek Comparing the two Iterates slower, so it's easier to

    keep up PHP has way better support for reflection than Javascript (Laravel dependency injection) Magic methods can be used in creative ways (Laravel "User::where()") Standard lib functions are inconsistent and aren't methods on their respective primitives (e.g. array_* and str* families) Anonymous functions require the `use` statement and have no shorthand notation 4. Language
  10. 1@bryantebeek Comparing the two 4. Language $message = 'Hello'; hello(function

    ($user) use ($message) { return "$message $user!->firstname"; });
  11. 1@bryantebeek Comparing the two 4. Language const message = 'Hello

    World' hello(user !=> "${user.firstname} ${message}")
  12. 1@bryantebeek Comparing the two 4. Language $numbers = [1, 2,

    4, 8]; !// 16, 8, 4, 2 implode(', ', array_reverse(array_map(function ($num) { return $num * 2; }, $numbers)));
  13. 1@bryantebeek Comparing the two 4. Language const numbers = [1,

    2, 4, 8] !// 16, 8, 4, 2 numbers.map(num !=> num * 2).reverse().join(', ')
  14. 1@bryantebeek The two at Lifely So why did we switch

    to Node.js instead of PHP and why you probably shouldn't do the same?
  15. 1@bryantebeek The two at Lifely Why we made the switch

    In 2014 Node.js was the all new hype Created bundlin.com in Node.js One of our early customers requested we use Meteor We then used Meteor for one more application Client and server written in the same language MongoDB + NoSQL
  16. 1@bryantebeek The two at Lifely Why you probably shouldn't Performance

    is more dependent on how well the backend has been written instead of the actual core architecture Node.js is not magically going to make your application fast PHP ecosystem has great frameworks and CMS-like systems Laravel, Symfony, Wordpress, etc. Easy to deploy, focus on the actual application being build