Node.JS VS PHP — in a nutshell

Node.JS VS PHP — in a nutshell

By
Ashley Sanders

Node.JS and PHP are both engines that power the back-end of dynamic applications, but they have very distinct differences. Here’s a comparison and why we chose to use Node.js as our tech of choice for Hi5.

PHP is one of the most mature, commonly used server-side scripts on the web. Node.js is not a script but a back-end development environment that’s written in JavaScript OR simply a strictly client-side script. Node.js made it possible to use JavaScript on the back-end when it was introduced in 2009, bringing the rise of web applications with entirely JavaScript-powered stacks.

WHAT IS NODE.JS?

JavaScript is a scripting language that typically runs in the browser and allows web pages to be dynamic and interactive, but ever since the release of Node.JS, it became possible to perform asynchronous coding with JavaScript on the server side and client side. Node.js is a development and runtime environment with a seemingly unlimited array of available frameworks that can run on top of it. Functioning uniquely on a single main thread for request execution.

WHAT IS PHP?

PHP is a scripting language that quickly became the industry standard back-end language of choice for developers after its initial release in 1995. A vast majority of sites on the web today run on PHP, due in large part to its popularity as the technology of choice for content management systems like WordPress, Drupal, and Joomla. As well as a number of modern frameworks such as Laravel, Symfony, and CakePHP that have taken full advantage of this languages power. Running on a multi threaded I/O blocking execution.

MAJOR DIFFERENCES

  • Runtime environments. While both JavaScript and PHP can be embedded directly into HTML, they both need an interpreter in order to run. PHP has long been readily straightforward to install and use, while being powered by the Zend engine. Node.js is a runtime environment for JavaScript on the server side, powered by Google’s V8 JavaScript engine.
  • Concurrency. PHP, like most server-side languages, uses multi-threaded, blocking I/O to carry out multiple tasks in parallel. JavaScript is unique in that it uses a few tricks, namely event loops and Node clustering, to achieve an event-driven, non-blocking I/O execution model that uses a single main thread of execution. PHP is a mature language and has found its own way to achieve asynchronous processing — most notably through the HHVM project released by Facebook.
  • JSON. JSON “JavaScript Object Notation” is a lightweight data format that gives Node.js an edge when dealing with JSON. While PHP can work with JSON, it’s more situational.

WHEN SHOULD YOU USE NODE.JS OR PHP?

You should consider PHP if your project involves:

  • Software stacks like the LAMP stack (Linux, Apache, MySQL, PHP)
  • Content management systems like Wordpress
  • Servers like MySQL, SQL, MariaDB, Oracle, Sybase, and Postgresql etc.

You should consider Node.js if your project involves:

  • Software stacks like the MEAN stack (MongoDB, Express.js, AngularJS, Node.js)
  • Dynamic single page applications (SPAs)
  • Front-end technologies like jQuery, AngularJS, Backbone.js, Ember.js, ReactJS etc.
  • Server-side technologies like Node.js, MongoDB, Express.js, etc.

Note that neither of lists above are extensive, or dutifully explain the extent to which you can use these two technologies. The choice to use Node.js as our back end at Hi5 came down to these simple points.

  1. Allowed us to write a clean single language API to connect all 3 of our platforms (Web, Android, iOS) whilst taking advantage of its beautifully clean JSON handling methods
  2. Easier to secure with standard SHA256 encryption when combined with MongoDB.

This isn’t to say Node.js is better than PHP, it just suits our needs.