by jay patel
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 will compare two back-end technologies PHP vs NodeJS.
PHP 7 VS NODE.JS: TERMINOLOGY DIFFERENCES
PHP is a programming language. Node.js is not a programming language; it is rather an interpreter of JavaScript code (due to the Google Chrome V8 engine) to the operating system installed on the server. But Node.js is more than just that because it is extended with the libuv library that focuses on asynchronous I/O.
To execute JavaScript code on the server, one needs a Node.js installer.
PHP cannot work without a web server. Node.js has built-in tools for creating servers, hence it can work without the help of external servers. However, as a rule, Nginx server is used as a reverse proxy before Node.js server on a production hardware server.
PHP was created in 1994, Apache – in 1995, Javascript – in 1995, Nginx – in 2002, and Node.js – in 2009. Let’s take a look at the history of creating Node.js and reasons for its development.
PHP 7 VS NODE.JS: BEHIND NODE.JS CREATION
As everybody can see from the first presentation of Node.js in 2009, Ryan Dahl, the creator of Node.js, criticized:
The limited possibilities of the most popular web server in 2009, Apache HTTP Server to handle a lot of concurrent connections (up to 10,000more);
The most common way of creating code (sequential programming), when code either blocked the entire process or implied multiple execution stacks (read as “more hardware and software”, more money) in the case of simultaneous connections.
As Ryan Dahl noted, Node.js and Javascript were able to solve this problem at that time at no extra cost:
Node.js provides a purely evented, non-blocking infrastructure to script highly concurrent programs.
Javascript is designed specifically to be used with an event loop: anonymous functions, closures; only one callback at a time; I/O through DOM event callbacks. The culture of JavaScript is already geared towards evented programming.
Ryan Dahl‘s presentation was regaled with ovations. One of the most common web applications' performance problems was resolved! No additional hardware! No additional monthly hosting costs! The only strict requirement was retraining programmers to teach them using event loops, callbacks, and non-blocking I/O.
The disadvantages of being single-threaded: your code will run in single thread only and so you can’t do anything complicated. If your code needs to process data for each request and it’s going to take just 10 milliseconds and there are 1000 concurrent connections, it will take 10 seconds to finish all of them. It’s pretty bad response time, isn’t it?
Some large companies expressed interest in the implementation of Node.js into their live project. As was reported, the transition from Rails to Node.js improved the scalability of LinkedIn’s mobile backend infrastructure. There’s been a lot of talk about PayPal moving from Java to Node.js for an application platform.
In his recent interview (2017), Ryan Dahl has admitted that,Node.js "is not the best server side system ever ".
PHP 7 VS NODE.JS PERFORMANCE
In 2015, PHP 7 with new long-expected features was introduced .
PHP 7 is based on the PHPNG engine that speeds up PHP applications more than the previous PHP interpreter (Zend Engine 2.0). Thanks to PHPNG, your apps see up to 2x faster performance and 50% better memory consumption than PHP 5.6
Source: zend.com/en/resources/php7_infographic
With PHP 7, possible differences in performance are already not an issue when one compares Node.js with PHP.
But even earlier, in 2013, Phil Sturgeon made a test and concluded: "PHP is not sucking as bad as some people would expect. Removing the blocking PHP approach (because obviously, it's slow) and running just the other three scripts [PHP 5.5.5 + ReactPHP + phpQuery] looks like this [take a look on the image below]. Look, they're the same. At this point, it is just a network test. The speed between the two systems for handling this specific task is essentially identical".
Need Node.js or PHP developers? Hire a dedicated team!
PHP 7 VS NODE.JS: PHP IS ALIVE AND HAS LEARNT ITS LESSONS FROM NODE.JS TO BE STRONGER THAN BEFORE
A lot has changed since 2009. The WebSocket protocol was standardized in 2011 and NGINX server started to support it. PHP programmers have learned to use event loops,callbacks, and non-blocking I/O with ReactPHP.
So, today’s experienced developers can choose what tool to use for any particular project. What do they take into account when considering what tool to use?
Experienced software developer (10 years of experience with PHP, 1 year – with Node.js) Review: For some tasks, Node.js may be faster than the “standard” webserver with PHP because it runs as a single thread with non-blocking IO for each connection, hence there is no memory overrun. Due to this, Node.js is useful when there is a need to process data in real-time (chats, games, video, big data streams without logic). However, Node.js can also be used for creating CMSs, e-commerce, and other web applications, which are usually developed using PHP. Node.js is also able to perform high-load tasks, but these tasks should be moved away from the main thread using appropriate tools such as callbacks, workers etc.
On the other hand, tasks for which Node.js is an excellent choice can be performed using PHP. For example, ReactPHP enables developers to write PHP-based socket server to process requests constantly as well as Node.js does it (yes, Node.js is faster, but the fact is that PHP can also do it). The same thing with Workers (the classes responsible for running asynchronous jobs and synchronizing their results) or Amp (libraries that are used for writing non-blocking asynchronous code). Hence, it is easy to create long running processes using PHP. Additionally, there are a lot of tools for supporting and managing these processes (such as supervisord ).
Finally, Node.js can be used as complement to the PHP (or to another programming language) with the aim of reducing load on a server and performing program (or, as one can say, PHP can be used as complement to Node.js :))) For example, the first version of a website was built in PHP and then the client asked to develop a real-time system that gets data from stock data systems. I would prefer to develop that real-time system as a separate application using Node.js (and then integrate it into the PHP-based application).
So, the same tasks may be performed either with PHP or with Node.js. The question "what tool to use" is a question of personal preferences. I use Node.js for tasks involving big data flows and PHP for tasks involving complex logic, high-load tasks, for dealing with external utilities, applications, and OS. PHP has a lot of different libraries, frameworks, and it is more standardized than Node.js (however, Node.js is not far behind and continues to gain momentum). In general, I think it is a good idea not to counterpose them, but use them cooperatively.
software developer , participant and award winner of various hackathons (8 years of experience with PHP, 1 year – with Node.js): Comparatively low entry barrier for writing PHP code means there are many PHP specialists on the market, hence, it is pretty easy to find developers for PHP-based projects. Due to age factor, PHP has more production-ready modules, frameworks, and CMSs. It means if a client needs a product and there are ready solutions in PHP, then it is better to use PHP because it will be cost effective.
I think the entry barrier for writing Node.js code is higher. Node.js uses JavaScript, but it does not mean that any front-end developer can easily start writing back-end using JavaScript. And it does not mean that any front-end developer can use the same code snippets both on the front-end and back-end.
PHP and Node.js are tools that can very often be used interchangeably for the same tasks. However, Node.js is often used for real-time applications, web sockets and workers (especially, persistent workers), and rarely for high-load tasks and computation. From the scalability perspective, there are no big differences between PHP and Node.js, it is more important to consider the project’s architecture.
It is always interesting to hear what other experienced developers think. Here is what we have gathered from the web.
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)
Oracle
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
One of the main advantages of NodeJS is the support of multi-threading. While it is a necessity in browsers, it is not that much needed in web development process.
The scripting language does not need to be threaded”
Rasmus Lerdorf
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 learns for JS developers.
Here is the PHP vs NodeJS comparison table of supported technologies:
|
PHP |
Node JS |
CMS |
Magento, WordPress, Opencart,Drupal, Joomla, PrestaShop |
Apostrophe2, Ghost, KeystoneJS, enduro.js, Pencilblue |
MVC frameworks |
Symfony, Laravel, Yii, Codeigniter, Zend, Phalcon, CackePHP |
Koa JS, Express JS, Sails JS |
Realtime |
Ratchet, Wrench, Elephant.io, Socket.io |
ws, Sockjs, Socket.io |
REST API |
RestClient, Guzzle, HTTPFUL |
Restify, Loopback |
Scaffolding |
symfony+, laravel+ , yii+, CackePHP |
Yeoman |
HTML templating |
Twig |
Jade |
Horizontal scaling implementation |
Elastic beanstalk, varnish |
Cluster mode, Amazon Elastic Beanstalk |
Load balancer support |
+ |
+ |
Queues |
+ |
+ |
Multiple drivers support DB, storage |
+ |
+ |
Full-text search |
+ |
+ |
Profiling |
Xdebug, Blackfire, XHProf, XHGui |
Built in profiler |
Caching |
Redis, Memcache |
Redis, Memcache |
CI support |
Travis CI, Codeship |
Travis CI, Codeship |
QA |
PHPUnit |
Phantom.js |
PHP has won in almost every category of our PHP vs NodeJS comparison. PHP is more popular and easier to learn, yet it supports a significant amount of professional programming technologies and techniques. There are plenty of sources where you can get assistance and help and the deployment process is so much easier than Node.JS.
For a long time PHP was the butt of many language jokes, but I honestly feel that it’s becoming not only a popular language but a powerful one. PHP7 is great. The speed boost is one thing, but having optional support for full type hinting is a game changer. We’ve also got modern tools like Laravel and Composer, breathing new life into the language and its supporting community.
However, don’t discount Node.JS yet. Despite its steep learning curve, it has some really serious advantages. With the help of AJAX and HTML5 you can create very efficient apps and once the code is cached, the only thing that keeps transferring is data.
Ref : belisoft
Your email address will not be published. Required fields are marked *