DEV Community

Discussion on: Node JS vs PHP

Collapse
 
szilardszabo profile image
SS • Edited

Node.js is not a framework in any sense. It is a run-time environment that has a javascript interpreter at its core.

PHP is on the other hand is not a general purpose language.
It is in practice not well suited anything other than web development.
Can you tell me any other typical usage of the PHP language? No you can't!
It was originally developed as a simple scripting language only for web development built on top of C libraries and functionalities.
In so many respects it still a scripting language.
From this perspective PHP can be more easily called as a "web framework" than Node.js.
Actually Rasmus Lerdorf the inventor of PHP said it a few times that PHP is a web framework.

Actually in this respect Node.js is exactly the same, it main purpose to provide you with a scripting language and its runtime interpreter is built on top of some C libraries and functionalities.
So in this respect there is no difference at all...

Anyway, all of this actually quite the opposite of what your are writing.

Please note I have no preference in PHP or Node.js, I am using both and I am not biased towards any of them, so it is not about saying that one is better than the other. What I am writing are just simple facts.

What you need to be very careful of is that if you look at laravel and an express code that looks very similar, they actually can result in a very different way of execution flow in the runtime. For an inexperienced developer this can result in a very unexpected behaviour, especially when it comes to javascript as it executes very differently from PHP. This is what needs to be emphasised in a comparison, and this is what is not there in your article at all. I suspect the reason of this - and it is because of my experience with so may people - is that you do not know any of the reason of this big difference. You have no idea of most probably...

Also I don't see any evidence that Node.js scales better or faster than PHP, it really depends of the use case.
They both scale very well and fast enough provided that used for the right task which is different for both.
(Actually if you want to compare the differences, you can write about the very different type of tasks the two things are good for, and then you and your readers would start to understand the difference.)

Node.js is by default only fast if it does not do any CPU heavy computation, so in this respect in generic case it has exactly the same performance as PHP. (As PHP also not very good for CPU intensive stuff)
Node.js is only fast and scales well in handling concurrent requests if nothing CPU heavy is involved, which is a special case. So you can't say it is fast in general. Only in this special case.
The big difference here is that if you do very CPU intensive task with PHP it can still survive because of it's designed for multi threading on the other hand Node.js by default with its single threaded event loop just stop serving any request if a CPU heavy task hold up the event loop. Its single thread would become unresponsive.
Notes:
1, Multithreading in PHP means that when running as a webserver module that the webserver has a thread pool of your script ready to serve requests. This means that the same script you write runs in multiple instances.This is not natively supported with Node.js when you simply serve the requests using its http and similar modules or express.
2, CPU intensive task is for example a task that needs a lot of number crunching, like encryption, calculating complex equation, running recursive calculations etc..

If you want to compare the two thing and emphasise the big difference between them - and there are huge differences between them - then you really need a different approach.
I recommend you to gain more fundamental knowledge in both before try to compare.

What you need to talk about when it comes to the huge difference between the two things is their architectural design.
In short Node,js architecture follows single threaded event loop model that is very different from PHP runtime model which natively supports multi threaded synchronous execution flow.
This is one huge difference and the cause that the two thing behave very differently when it comes to scalability and speed in very different scenarios of course.

I advise you and everybody who wants to know the real difference to start digging into these topics to understand the basics of program languages and the design of their run time architecture.
Unfortunately of course it needs competency in these fields which is unluckily very scarce.

This kind of inadequacy and inability to properly compare things, giving false impressions and spreading false information are all the result of the so many so called developers today in this industry lacking the most basic knowledge of the field which is very bad news for competent, educated developers.

Your article in this current form is written very inadequate and incompetent way, giving the usual false impressions to everybody about PHP and Node.js.
What worse is that it is in absolutely in sync with all the popular false beliefs and false information circulating everywhere on the web about these two thing,

First of all I advise people to start using these things as they are without any frameworks on top of it. E.g. Node.js without express and PHP without laravel or similar to understand what is the native behaviour of these languages and gain some basic understanding, because lot of people confuse a framework with a program language and its run time.