Almost every day there are some new technologies emerging, that are trying to change the web landscape. Server-side of the web development also is divided, there are long-standing heavy-weights such as Java, C, and Perl and newer, more web-focused languages like Ruby, Clojure and Go. But how to select a perfect solution for your project? We will compare two back-end technologies PHP vs NodeJS. We hope we won’t start a holy war.
First of all, let’s define PHP and Node.js. PHP is a server-side scripting language. It was created in 1994 by Rasmus Lerdorf in 1994 primarily for web development. Originally PHP stood for Personal Home Page, but now it stands for a recursive acronym – PHP: Hypertext Preprocessor.
Usually, PHP is processed by an interpreter, powered by the Zend Engine, that is installed on web servers such as Apache and Nginx. Also PHP code can be embedded into HTML or HTML5 markup. This flexibility contributed to the popularity of the language, PHP is now used on more than 80% of web servers.
Node.js is an open-source, JavaScript run-time environment used to execute JavaScript code on the server-side. Node.js development process has changed the paradigm that JavaScript is used primarily on the client-side. That’s why Node.js has become one of the foundational elements of the “JavaScript everywhere” paradigm. Node.js was created by Ryan Dahl in 2009.
It is powered by Google’s V8 JS engine, that is the same engine that is used in Google Chrome web browser. This JS runtime environment doesn’t need a separate web server or other dependencies, there are built-in libraries that take care of that. Compared to PHP, Node.js is relatively young, however, it is already well recognized and used by giant companies like Microsoft, Yahoo, LinkedIn, and PayPal. For a clearer view, here is the PHP vs NodeJS comparison of the popularity indicators in the form of a table:
Benefits of PHP
Some developers say that PHP is much easier to use then Node.js. Their arguments are:
It’s easier to configure the development environment for PHP
Node.js requires more code
In order to code on Node.js, you have to understand callback functions and blockings
All internet hosting services support PHP
Supports more frameworks and CMS
Official code organization recommendations (PSR)
PHP has a larger library of instructions and frequently asked questions (there were plenty in 20 years)
The PHP developers community is a massive and diverse group of people, they are constantly re-visioning and updating libraries, frameworks and other PHP components
You should consider using PHP when your project includes:
CMS technologies such as WordPress, Drupal, Joomla, etc, even if there is only a part of your project includes these technologies (for example blog, admin page, online store etc.)
If you are using a relational database – go with PHP.
To sum up the whole server side of this PHP vs NodeJS comparison, PHP supports following database management systems:
MySQL / MySQLi
SQLite
PostgreSQL
Oracle (OCI8)
Microsoft SQL Server
Sybase
ODBC
mSQL
IBM DB2
Cloudspace
Apache Derby
Informix
Ovrimos SQL
Lotus Notes
DB++
DBM
dBase
DBX
FrontBase
filePro
Ingres II
SESAM
Firebird/InterBase
Paradox File Access
MaxDB
PDO
Benefits of Node.JS
One of the main advantages of NodeJS is the support of multithreading. While it is a necessity in browsers, it is not that much needed in web development process. A lot of developers choose Node.js over PHP. Here’s why:
Built-in server support
A single syntax for client and server side of the website. This improves the reusability of the code and makes the work of a full stack developer easier
Module caching – modules are downloaded and initialized when they are called for the first time, afterward they are constantly available
Stream module makes it easier to work with large files
Node has an almost identical syntax to JavaScript, thus it easy to pick-up and learn for JS developers.
Benchmark
It is a good idea to choose a winner in PHP vs Node.js based on the features and benefits. However, it is always better to see how they are performing back to back, PHP vs NodeJS. We have created two different test cases and will run them on the same machine.
The test bench configuration:
VDS
CPU – 1 core, 2GHz
RAM – 1GB RAM
Storage – 10GB SSD
OS – Debian 8.6
PHP 7.0.22 FPM
Node.js 6.11.2
PHP vs NodeJS – First test
This test will show us how well PHP and Node.js are working with arrays, string concatenation, network I/O, and arithmetics. Results for PHP:
For nodejs
As you can see PHP is faster than Node.js in:
Concatenation of strings
Filling array
Filling associative array
Reading the file
MySQL query
Node.js is faster than PHP only in adding numbers.
Comments (0)