NODE.JS vs PHP comparison - get the job done purpose

Yuil Tripathee
5 min readAug 31, 2019

--

source: https://firebearstudio.com/blog/wp-content/uploads/2015/10/Node.js-vs-PHP.png

I had to do the comparison and bench-marking research over to implement a simple back-end during my early internship days when I was figuring out how the basic server side systems work. I’ve got a web scraper to mine up data from local eCommerce in the city using Python’s Beautiful-soup library. Got my data in MySQL database, found a way to get the data into the database in organized manner using database connection and queries and finally, I was assigned to build a back-end out of the data I have collected in the database.

Benchmarks works first

Benchmarks allows you to know how well will your back-end setup will perform in the computer at the first hand.

#1 Benchmark: Simple HTTP request handling rate

benchmark comparison for request per second handling capability for different back-end solutions

Here are the findings:

  1. This HTTP-controlled “hello world” benchmark used Zend PHP 5.6.6 with OPcache enabled.
  2. The test was done using the Apache ab benchmarking tool.
  3. The performance of Zend PHP is less than half of Node.JS.
  4. The performance of HHVM is about 74% better than Zend PHP.
  5. The performance of HHVM is very close to Node.JS, but Node.JS is still about 17% faster.
  6. The performance increase when using Wordpress with HHVM is about 47%.

#2 Benchmark: HTTP + CPU tasks benchmark

average response time comparison (2015 benchmark — but stats not so far)

Since, things has been the same with the benchmarks, let’s see how those things works:

Working methodology between traditional server systems and node.js

Here are the finding of this benchmark:

  1. The HTTP bubble sort-job benchmark used Zend PHP 5.5.7 with OPcache enabled.
  2. The HTTP bubble sort-job benchmark used Zend PHP 5.5.7 with OPcache enabled.
  3. The HHVM performance is similar to Node.js up to 1,000 sort elements, but with 10,000 sort elements, Node.js was about twice as fast HHVM (not visible on this chart).

#3 Benchmark: Comb-Sort Strict CPU Test

combo sort strict CPU Test

HHVM is seven times faster than plain PHP (by system time), but Node.js is more than five times faster than HHVM in this number-crunching test. In terms of RAM usage, HHVM is much more efficient than PHP, but Node.js is even better.

#4 Benchmark: This might help

job trends comparison

Some notable matters

Optimal Server side performance

The choice of PHP or Node.js is totally a decision which is based on the need of the application/website, if we need a heavy data lifting and has to handle multiple concurrent connections requiring quick turnaround time at consumer app side Node.js has the upper hand, though there has been enhancement at PHP frameworks side which can also handle concurrent connections, still Node.js is a clear winner. Node.js provides a purely event-driven non-blocking infrastructure to script highly concurrent programs.

Code compilation performance

The standard PHP Zend runtime uses an interpreted compilation strategy, leading to less optimised code execution than a good JIT-(Just-in-Time)-based runtime which is at the core of Node.js, it uses V8 JS Engine for JIT compilation giving Node.js extra mile edge in starting up time.

Node.js uses Just-in-Time compilation with the V8 JavaScript Engine. This strategy for dynamically typed languages has proven itself but does often increase startup time a little. PHP with HHVM & HACK open source run time alternative is catching up with Node.js as HHVM uses a Just-in-Time (JIT) compilation approach to achieve better performance.

Multitasking

As we have spoken that Node.js is super efficient in handling multiple concurrent request, it is made possible because it uses a non-blocking event loop (which utilises single thread)as compared to PHP Zend Runtime which uses a blocking process, due to this limitation PHP has to depend on multiple threads(process) to serve the web services request. If there is a heavy lifting done at user side and they are putting multiple connection request at a given point of time, server can run out of resource to address those process request, causing delays in HTTP response to the client side web/app.

Web servers like Apache and NGINX have ways to improve the PHP multi-tasking performance to some extent, but these are more limited than true language support for multi-tasking. Facebook HHVM project released in 2014 is trying to remove this limitation at PHP side .

Many people has done some performance benchmark testing on Node.js Vs PHP Vs HHVM(supporting PHP) based on:

  1. HTTP communication
  2. HTTP and CPU task
  3. Combo sort strict CPU test

If you mind?

Where PHP wins:

  1. Mixing code with content.
  2. Deep code base.
  3. Simplicity (sort of).
  4. New code is helping it catch up.
  5. No client app needed.
  6. SQL
  7. Speed of coding.
  8. Competition (between frameworks)
  9. Portable solution
  10. Designed for the web

Where PHP loses?

  1. Inefficient separation of concerns.
  2. Outdated client server model.

Where Node wins?

  1. Separating concerns.
  2. Newer code means no more modern features.
  3. Complexities of closures and more.
  4. Dozens of language options.
  5. Service calls are thinner than fat PHP calls.
  6. JSON
  7. Raw Speed
  8. Solidarity
  9. Fast server side solution
  10. One language across the stack
  11. Flexibility

Where Node loses?

  1. Less efficient in handling CPU intensive applications.
  2. Lack of maturity.

Considering the users

Giants using PHP:

  1. Facebook
  2. Wikipedia
  3. Google (uses HHVM but not the main platform)
  4. Yahoo
  5. Wordpress (giant of internet traffic)

Companies using Node.JS

  1. Netflix
  2. Trello
  3. Paypal
  4. LinkedIn
  5. Walmart
  6. Uber
  7. Medium
  8. Groupon
  9. Ebay
  10. Rakuten

My choice today: after some experience

I got familiar with Golang few months back, so i prefer programming systems level stuffs, something like block-chain things, as well as REST API and bunch of my research and fun projects.

But, for complete full stack setup, I prefer to use Django stack (for both API and Web app as much as possible) since I am used to with Python, a significant advantage over hopping into completely new arena for no reasons at all.

I recommend Node.JS over PHP as benchmarks are sound, you still have to work around with JavaScript as a full stack developer, the significant advantage over shifting mind between two languages. PHP seems to be fading nowadays and other solution have promising features.

If you are interested in something else, I mean different taste of getting things done, consider Ruby on Rails.

--

--

Responses (1)