15 August 2019
PHP vs Node.js: how to choose. CTO’s guide
PHP and Node.js are two of the most popular choices when it comes to backend technologies for the web. PHP has been around for a long time and established itself as the most popular backend language on the web, while the Node.js platform is considered the new kid on the block, gaining the support of vast community and many innovative companies. How to choose between PHP and Node.js? What are their pros and cons? Why are some software engineers moving to Node.js? The CTO and developers from The Software House are offering their opinion.
Even though technically they are not equivalents – one of them being a programming language and another an environment based on JavaScript – it’s easy to see why PHP and Node.js are often compared and weighed against each other. After all:
- they are backend technologies used for server-side scripting,
- both are open-source,
- and both are highly specialized in web development.
While the approach they use may differ, both PHP can Node.js code can be used to create efficient and scalable web applications. Before we compare them directly, let’s take a closer look at them one by one.
PHP – the original go-to backend solution reinvented
Out of the two, PHP is by far the older one. It was created back in 1994 by Rasmus Lerdorf, who simply needed a tool to maintain his personal web page. This very first version of PHP was already capable of supporting dynamic web pages, including form handling and the ability to embed HTML.
However, Lerdorf never intended for PHP to be an actual programming language. When the technology was released as an open-source program, it took a new life on its own and new contributors began adding more and more features. PHP was fairly easy to use for web development, as a tool created specifically for that purpose, but due to its organic and unstructured early growth, it was quite inconsistent (e.g. misleading naming of functions or parameter order).
Nevertheless, PHP proved extremely popular and the relatively short learning curve made it possible for even inexperienced developers to use it efficiently. In addition, being open-source, it could soon be found on the majority of web servers worldwide (it’s a server-side language of choice for around 79,1% of all websites) and used as a basis for a range of software aimed at making web development of various types of software products easier. Here are some numbers:
- The majority of popular content management systems (CMS) – WordPress, Drupal, and Joomla among others – are written in PHP.
- In fact, as of 2019, the PHP-based WordPress accounts for as many as 61 percent of all websites that use any kind of CMS.
- Three out of four most popular eCommerce platforms among the TOP 1 million websites are all written in PHP: WooCommerce (a WordPress plugin), Magento and OpenCart.
With the subsequent releases – as well as the emergence of web-focused PHP frameworks such as Symfony, Zend, or Laravel – PHP got gradually more consistent and was provided with tons of out-of-the-box solutions for repetitive webdev challenges (e.g., see the current list of Symfony components).
Node.js – the answer to the modern web’s needs
Compared to PHP, Node.js is still a relatively young technology. It was released in 2009, bringing attention to the idea of using JavaScript on the backend.
In the early days of web development, the majority of developers used JavaScript code merely for form validation and basic UI interactions (with occasional AJAX being the extent of its might). Node.js pushed the “JavaScript Everywhere” paradigm even further, at last making it possible to center the entire web application development around a single programming language.
Taking advantage of JavaScript’s single-threaded nature, Ryan Dahl created an environment that is asynchronous by design. This particular solution made Node.js the technology of choice for applications, which involve a lot of simple real-time interactions. As a result, Node.js became the backbone of popular products from companies such as Netflix, PayPal, LinkedIn or Uber.
But developers love Node.js just as much as innovative companies. Not sure? Well, according to this year’s Developer Survey by StackOverflow:
- Node.is the most popular technology in the “Other Frameworks, Libraries, and Tools” category (49.9% of respondents use it).
- It’s also the 6th most loved technology in the same category (with 72,1% of users expressing their fondness for it).
- Finally, what’s maybe the most important piece of information, Node is also the 1st most desired technology (17,5% of all participants want to learn it).
PHP vs Node.js – comparison
Before we ask our people about their opinion of PHP and Node.js – a quick comparison of various characteristics, including various aspects of the PHP vs Node.js performance issue.
PHP | Node.js | |
Release year | 1995 | 2009 |
LTS | Yes | Yes |
License | PHP License / Zend Engine License | MIT License |
No. of packages | 233,625 (Composer, as of August 2, 2019) | 1,047,679 (npm, as of August 2, 2019) |
No. of devs | Up to 5,000,000 | 75,000 |
No. of stars on Github | 24,245 (the interpreter, as of August 2, 2019 ) | 63,220 (Node.js JavaScript runtime, as of August 2, 2019) |
No. of questions on Stack Overflow | 1,299,465 (as of August 2, 2019 ) | 285,874 (as of August 2, 2019 ) |
WebSockets | Ratchet | WebSocket/Socket.io |
Load balancer support | Yes | Yes |
gRPC | Client only | Client/Server |
Smart Contracts | Ethereum-PHP | Truffle |
Queues | Yes | Yes |
IoT | PHPoC | Node-RED |
Serverless | AWS Lambda, Azure Functions (experimental) | AWS Lambda, GCP Functions, Azure Functions |
Architecture | Each request is isolated, so a single error doesn’t impact other users. Requires more resources (RAM, CPU). | Single server is shared between requests, so unhandled error in one, may have an impact on others. Requires less resources (RAM, CPU) |
Multiple drivers support database | Yes | Yes |
Request handling | Mostly synchronous. Requires special libs for asynchronous calls | Mostly asynchronous |
By the way, did you know that it is possible for PHP code to work asynchronously?
Should I choose PHP or Node.js for my project?
You should already have a pretty good idea about this issue. Let’s see what Marek Gajda, TSH’s CTO, has to say:
PHP – perfect for standardized and typical case scenarios
“As the older and more battle-proven technology, PHP shines in projects that do not require developers to reinvent the wheel, such as eCommerce stores, CRM, CMS, warehouse systems or any other business system based on forms and databases. This is where PHP coding does best, simply because there is a whole lot of quality ready-made components to make them as well as strong community support for it.”
Node.js – ideal for highly interactive web applications
“On the other hand, when you’re looking to make a very innovative and interactive project, Node.js may be the better choice. It’s a modern technology, which also attracts like-minded devs. They are up-to-date with all the latest trends”.
Adam Polak, TSH’s Head of Node, seems to agree:
“Node.js’s architecture does better with apps that are expected to be highly interactive. All sorts of dashboards and widgets that require real-time updates (bots, fintech apps, chats, surveys) are perfect for Node.js. Another important point to consider is Node’s tendency to support all the latest novelties, such as the serverless architecture or Ethereum smart contracts.”
When is it a good idea to move from PHP to Node.js (and when it is not)?
Last but not least, let’s discuss one of the hottest topics in the software development market – moving to Node.js. As the popularity of Node.js is growing, more and more developers are considering such an option. Among them are many PHP developers as well. One of the reasons is the salary: according to PayScale, an average Node.js developer in the U.S. can make as much as $104,964 – up to 40 percent more than an average PHP developer ($65,565). But this is not the only reason.
At The Software House, there are a couple of developers who decided to make the journey from the world of PHP development to Node. What were their motivations?
PHP’s growth being unsatisfying
Mariusz Richtscheid is working at TSH as a Node.js developer. What made him move from PHP to Node.js?
“I was unsatisfied with the growth rate of the popular PHP frameworks as well as the language itself. Consequently, I found some of the projects I worked on to be quite boring and repetitive. Node.js provides me with more challenges, novelties, more exciting projects and a vibrant community.”
Node.js’s flexibility
Szymon Piecuch is also a big fan of how quickly Node.js adopts new solutions. But he also appreciates Node.js’s ability to adapt to all kinds of unusual projects.
“Node.js is fast and flexible. It makes it easy to create very responsive real-time web apps. It may be a bit controversial, but I believe that in the future it will give you access to a much bigger variety of interesting projects.”
Quick adaptation
According to Tobiasz Warzyńczok, for an experienced backend developer who worked with JavaScript previously, migrating to Node.js is fairly easy.
“I got an opportunity to rewrite a PHP code in an app into Node.js. I’ve always been something of a full-stack developer, so moving to another language was not an issue for me. JavaScript is a bit of a double-edged sword – you can easily ruin a project with it, but you can also build something extremely interesting very quickly”.
The grass seems greener on the other side
But it isn’t all roses. There are still quite a lot of PHP developers who, all things considered, decided to stick to PHP. That’s what Szymon Szymański, Head of PHP at The Software House, has to say:
“Many PHP developers that switch their main technology from PHP to Node.js simply strive for adventure. They believe a new great journey waits for them on the other side. It’s undoubtedly true that the Node community has produced more packages, yet the language itself has flaws that quickly appear in bigger projects. That’s why many Node developers decide to write their apps de facto in TypeScript. Although TypeScript is transpiled into Javascript, it’s a different language by itself. Seeing that you need augmenting tools to assist your primary technology is disturbing for many PHP developers – who decide to stick to PHP.”
As you can see, not all PHP developers are all that impressed by Node. Many choose not to move even after careful consideration. This means that we can still not be sure what the future will bring. Will even more PHP devs decide to move, or perhaps Szymon’s arguments will triumph? One thing is for sure – the market of backend technology will still be diverse and very exciting in the future. What should CTOs choose for their companies then?
Building PHP and Node.js teams at your company
Ok, we know the most important differences between PHP and Node.js. We also have a solid grasp on why Node.js is currently trending among software developers.
TL;DR: usually, PHP works better when it comes to standardized systems based on forms and databases, while Node.js should be your choice if you’re thinking of highly interactive, modern apps working in real time.
This is why many developers (PHP devs among them) are seriously considering moving to Node.js. Therefore, if you consider building a Node.js development team at your company, you can definitely seize this opportunity. Having access to software developers from all the different technologies, you can use all the arguments presented above to inspire your employees to make the decision to migrate.
On the other hand, if you don’t need to reinvent the wheel and your application is a pretty straightforward eCommerce store, CRM, CMS, or warehouse system, you should rather stick with “good ole” PHP. With all the ready-to-use code components, the development will simply be much quicker. Systems such as WordPress, Drupal, or Magento have proven themselves capable fo supporting highly complex projects both when it comes to managing content as well as product and services.
Still unsure what's better for your project – PHP or Node.js?
Just contact us! The initial consultations at The Software House are entirely free of charge, with no strings attached. Regardless of whether you are interested in a PHP developer, or would like to create a Node.js application, you will find top-of-the-line professionals.