Can we (actually) compare PHP and NodeJS?

David Garcia
4 min readOct 27, 2020

--

Source: “Node.Js Vs PHP: The Ultimate Winner Is Out For Backend Development” @ excellentwebworld.com

There’s not such as a magic answer that covers every single case. You must understand your needs, how your project runs and which goal you are actually aiming to achieve.

Introduction

One of the most common posts I read online is always a direct comparison between PHP vs NodeJS, usually followed with a widespread question: which one of them you should use to develop your web project.

I already think there are far many posts for this, but just a few of them describe things properly and put the right points in context. So, here’s my contribution, hoping that it will clarify some points (and no, I am not going to tell you “use this one”).

What are PHP and NodeJS, exactly?

A programming language implies that you are writing lines of code that must be compiled into distributable software, no matter if it targets a unique operating system (like Windows, Mac or Linux) or if it’s cross-platform (working everywhere). One of the most common (and good) examples is C/C++, as you need to compile your source code and get a binary (executable) before installing or using it.

PHP is a general-purpose scripting language (that means is a language for runtime environments), and NodeJS is a JavaScript runtime environment (that means it’s the engine to run JavaScript code). In other words, none of them is compiling any source code, but using a runtime environment to “read and understand” your instructions on demand.

Source: “Let’s know what are the difference between Programming Language & Scripting Language” @ techytalks007.blogspot.com

OK… but which one is better: PHP or NodeJS?

Now that we have defined neither PHP nor NodeJS is a programming language (but scripting languages and runtime environments) let’s check what similarities and differences provide each one.

Similarities between PHP and NodeJS:

  • Both are based on scripting languages (PHP and JavaScript)
  • Both require runtime environments to run (PHP or NodeJS)
  • Both have established frameworks to expedite the development

Differences between PHP and NodeJS:

  • PHP runs synchronously; NodeJS runs asynchronously
  • PHP powers up a vast volume of projects; there are fewer NodeJS projects
  • PHP serves web apps through web servers; NodeJS serves web apps itself
  • PHP works just on the Backend; NodeJS can work for both the Frontend (building and exporting a Frontend web app) and Backend (by using NodeJS as an always-running software)
  • PHP is swift, but slower than NodeJS (due to the nature of sync operations); NodeJS works faster than PHP (due to the async nature of the engine)
  • PHP is better for higher usage of CPU and RAM; NodeJS is better for a higher volume of requests and data without running additional operations

Who uses each technology:

At the time of writing this post, there are a set of well-known projects using each one of these technologies. Some examples are:

  • PHP: Facebook, Wikipedia, WordPress and many more
  • NodeJS: Netflix, LinkedIn, PayPal, and many more
Source: “Double KO compilation ft. Justin Wong, Gootecks, Smug, Pepeday, and more shows one of the rarest moments in competition” @ eventhubs.com

Conclusion

As mentioned at the top of this post, if you want a straight answer for which technology you should use, then forget it. There’s not such as a magic answer that covers every single case.

You must understand your needs, how your project runs and which goal you are actually aiming to achieve. And if you are not a Software Architect with many years of experience and being able to prove a solid understanding of what is better for your business needs, then delegate this task to someone that has got enough experience working with both languages.

PHP has been the de-facto solution for many years, and it’s well established. Thus, many projects are depending on this language and it means there is a large number of opportunities. It might, eventually, evolve to another approach or disappear, but it won’t happen soon.

NodeJS implies you need to learn two different ways to develop using JavaScript code, but it might cover a wider range as the same developer can implement both the Frontend and Backend logic. However, the purpose of the language might not be the best one for your project needs, so don’t use NodeJS for building your company’s website but for building robust apps.

And what about me?

Personal experience using both languages is taken into consideration for evaluating how they work and which one is better to cover every project’s needs. So, I am using both languages. PHP is great for building backend software while NodeJS is very helpful to build awesome frontend web applications.

I believe PHP can bring a lot of flexibility if you develop micro-projects and micro-services, where each one works most efficiently and focuses on a single goal. Also, PHP can queue several operations into a queue system, and these can run in the background (such as Redis or RabbitMQ) by building their own consumers, which can be implemented as micro-services too.

I have also worked with both Frontend (with Angular) and Backend (with Express and KoaJS) NodeJS frameworks. I found it harder to use (especially when working on backend apps) as it requires a new way to understand how the processes work (due to we run asynchronous operations), but the final results of the NodeJS projects were faster and efficient.

Sources:

Official websites

Wikipedia:

Used images:

--

--

David Garcia
David Garcia

Written by David Garcia

Senior Software Engineer, Backend, NodeJS & Symfony developer, workaholic, passionate for new technologies and OSS contributor. https://linktr.ee/davidgarciacat

No responses yet