PHP 7 vs Node.js

Our team is experienced both in PHP Development Services and Node.js Development Services. We have a portfolio with both PHP-based applications and Node.js-based applications as well as mixed ones. What do we take into account when considering what tool to use?

Sep 05, 2017

PHP 7 vs Node.js

According to the “Developer Survey Results 2016”, which was conducted by STACKOVERFLOW, among over fifty thousand developers from all over the world, PHP is more widely used back-end technology compared to Node.js among back-end developers. Source: stackoverflow.com/research/developer-survey-2016

 

 

PHP 7 VS NODE.JS: TERMINOLOGY DIFFERENCES

  • PHP is a programming language for writing code and it is also at the same time an interpreter of PHP code to the operating system (like Linux or Windows) installed on the server. 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. Node.js is not just an interpreter because it is extended with the libuv library that focuses on asynchronous I/O.
  • To execute PHP code on the server, one needs to install PHP package  or Facebook HHVM package. To execute JavaScript code on the server, one needs a Node.js installer.
  • As a part of the real-world web applications, PHP code should work in conjunction with a web server. PHP has a built-in web server but it is not recommended for use on a production hardware server. As a rule, developers use Apache web server, Nginx web server or any other servers that support FastCGI or CGI protocols. As for Node.js, it 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. Why was it necessary to create Node.js? Let’s take a look at the history of creating Node.js.

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,000 or more);
  • 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.

 

PHP 7 vs Node.jsPHP 7 vs Node.js
PHP 7 vs Node.jsPHP 7 vs Node.js

 

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.

PHP 7 vs Node.js
PHP 7 vs Node.js
PHP 7 vs Node.js
 

 

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: the company was able to move from 30 servers down to just three, while still having enough headroom to handle roughly ten times their current level of resource utilization.  There’s been a lot of talk about PayPal moving from Java to Node.js for an application platform. The Node.js app was built almost twice as fast with fewer people, written in 33% fewer lines of code, constructed with 40% fewer files.

In his recent interview (2017), Ryan Dahl has admitted that Node.js "is not the best server side system ever. I think where Node has really shined is, weirdly, on the client side. So, doing kind of scripting around building websites. So, browser FI, for example. Kind of bundles up client-side Javascript. So, you can have all this server-side processing of client-side Javascript. And then, you know, maybe little servers to… maybe little development servers, and here and there, maybe some real servers serving live traffic. Node can be useful, or it can be the right choice for it. But if you’re building a massively distributed DNS server, I would not choose Node".

PHP 7 VS NODE.JS PERFORMANCE

In 2015, PHP 7 with new long-expected features was introduced (2x faster performance and 50% better memory consumption than PHP 5.6). Possible differences in performance is already not an issue when one compares “Node.js” technology with “PHP” technology.

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".

PHP 7 vs Node.js Perfomance

 

PHP 7 vs Node.js

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?

Andrey M., a software developer at Belitsoft Company (10 years of experience with PHP, 1 year – with Node.js): 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 in cases 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 heavy loaded tasks, but these tasks should be moved away from the Node.js’ 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 a 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 oppose them, but use them cooperatively.

Sergey K., a software developer at Belitsoft Company, 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.

PHP 7 vs Node.js

PHP 7 VS NODE.JS: SOME OPINIONS FROM THE WEB

Jonathan: We are planning to run a large-scale E-commerce marketplace (eventually a pool of websites, one for each country) and we are trying to decide on whether to use PHP + Apache Stack or go with Node.js. We plan to get 5000 peak simultaneous connections for our "product search" function. What would you suggest?

Thomas Hunter (a Senior Node.js Engineer): I'd lean towards PHP as you're probably not going to benefit from any real-time communication, shared data between different users, etc. Also, if Node crashes, it could cause a lot of trouble, especially since most of what you are doing is transactional, but if one PHP execution fails, it's much less dangerous. There's also a lot of PHP eCommerce applications and libraries out there already that you could make use of.

Azat Mardan: There are many better alternatives to PHP, e.g., Ruby on Rails and Django, however, nothing is as approachable as Node.js. I worked with many technologies including Ruby on Rails, Python, Java/J2EE, VB, ASP, Perl and of course PHP. However, my focus during the past couple of years has been dedicated solely to Node.js and front-end JavaScript frameworks like Backbone.js. So my opinion might be biased.

Juan (a developer with experience on Node.js, PHP, and Ruby): I developed an amazing and faster webRTC solution using Node.js and an astounding video portal using PHP that receives 1, 5 million visits every day; however I don’t think that I can achieve these projects’ goals by interchanging those technologies.

Laurens: I still doubt whether to use Node.js or native PHP sockets. Wouldn’t it make more sense to use default PHP instead of Node.js? As far as I know, Node.js is limited and barely has support for a good MYSQL connection, isn’t PHP more optimized for this? I know that Apache is slower than Node.js, but for what kind of application is it better to use Node.js? I do not have any idea of Node.js advantages over PHP Socket, perhaps the speed, but I will be using Nginx.

Gonzalo Ayuso (an experienced web architect and web developer): WebSockets with Rachet (PHP) works fine. I started to play with socket.io (node.js) some time ago and now I’m very comfortable with it. I haven’t done any in-depth benchmark to choose one or another, indeed. Socket.io for example, has a very fail-over system to work with old browsers (it works even with IE6), but Rachet works fine with newer ones. As you said, to perform traditional SQL operations is a bit of a nightmare using node. This is mainly because of the functional nature of js (OK js is not a fully functional programming, but it’s very close). I don’t have this problem because I always rely on backend server (PHP for me) and I only use node.js for the strictly real-time operations. My node.js servers for WebSockets are just a proxy and all the logic is bypass to the backend. Anyway, if you choose PHP or node.js for WebSockets you must take into account that you will need to handle two different servers. That’s means share authorization layer and things like that.

Since WordPress.com has moved to Node.JS, do you think Laravel will also look towards that option even though PHP 7 is here?

Dayle Rees (a Laravel Framework contributor and developer): 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. With this in mind, I think it’s unlikely that Laravel will move from PHP. I think it’s more likely to gain further integration with front-end tools to provide a complete application building platform. That’s where I see it heading in terms of future expansion. I’m sure Node will continue to excel when dealing with microservices and threaded applications.

RECOMMENDED FOR YOU

Lead Generation Design of The Best SaaS Websites

Prospects start evaluating a SaaS product at its website. The SaaS website can be an online lead-generation machine. The conversion and revenue of a SaaS company can be affected by footer design of its marketing (corporate) website. What do some of the best SaaS companies do with their websites’ footers? Look at this list to get and keep in mind some ideas while building or redesigning your SaaS website. ...

100% Remote Million-Dollar SaaS Companies

Companies that support remote (distributed, virtual, dispersed, or dedicated) workers and do it well seem to have a huge leg up on the competition. Let’s learn how these successful SaaS companies use global talents to increase software quality and reduce the cost of rent and office supplies: Basecamp, Buffer, Chargify, Convertkit, Ghost(pro), Groove, Hubstaff, Invision, Olark, and Zapier. We believe that you could utilize their experience and expertise to build your own full remote SaaS company. ...

SaaS Founders Who Became Rich Starting With MVP

Belitsoft has a huge experience in MVP software development for startups and prototypes for existing brands. MVP is a minimal version of the product with the minimum set of features that is enough to deploy and test the key hypothesis to solve problems of this product’ potential customers. Experts suggest that, in B2B, it’s not an MVP until you sell it. Viable means you can sell it. ...

Profitable SaaS Startup Ideas

The way to get profitable startup idea is not to try to think of startup ideas (including SaaS development). It's to look for problems, preferably problems you have yourself.  In fact, for many entrepreneurs, successful business ideas start out as solutions designed to address a challenge they face personally. Solving the problem that frustrates you - may be one of the best ways of finding an idea for your startup. Look at these software developers who acted accordingly before they found success.  ...

10+ Reputable Companies and Startups that Used Laravel to Build Their Websites

Whether great or widely known companies are using Laravel. Are any startups using Laravel Development? Are there any big and successful websites or enterprise applications built with Laravel framework? There are a ton* of excellent web projects created with Laravel and one can find the world’s best companies among their owners. ...

The Top 10 Advantages Of Laravel for Cost-Effective Web Development

In this article, we will list some of the most common problems, which very often arise during web development, and will demonstrate how Laravel Development enables us to solve all these common problems fast (read as “cost-effectively”). ...

Get A Free Quote

Do you have a software development project to implement? We have people to work on it.
We will be glad to answer all your questions as well as estimate any project of yours.
Use the form below to describe the project and we will get in touch with you within 1 business day.

Call us:
Phone - USA
Phone - BELARUS
Skype
EMAIL US:
Contact form