I am confused between php and node js . I want to know the difference between these two programming languages and also that why should i use this ??
To me, the big difference is that node is asynchronous, while PHP is not. If you're doing any database access in node, writing code to wait for the database to respond without going on to the next part of the logic is a shift in thinking in an asynchronous environment. Callbacks, promises, etc. are all options, but it's a definite shift from the norm if your norm is a synchronous language like PHP.
PHP if you:
Node if you:
They both can basically do the same thing, just one better than the other in some cases (like async). Just pick which one fits into your tech stack or programming preferences.
If it was all about the best choice for a present problem, the solution would become more clear as you define your scaling issues (ie: "My PHP-based chat app is slow, maybe I should switch to Node and SocketIO").
It's a matter of preference and your target market, but on the plus side, you don't have to preference every variable reference with a $ sign. Like seriously, what's the point of that? Such a silly waste of a key stroke.
Node.js is best, because of handling request.
Php is multi-thread-request model, means for each request its create thread to handle now if maximum thread limit exceed then your server not able to handle incoming request at that time,means incoming request to be wait for free thread.
But if you using node.js then you can handle multiple request at a time on the principal of single-thread-request-model. Its done by concept of asynchronous. Here we have a toll known as eventloop which will accept each request are coming and process if no need of any I/O block, if so then it will transfer the work to a thread present in thread pool. By that eventloop become free for take new incoming request.
Another thing is node.js is faster, because node.js by nature asynchronous means you can process your code without depend on another. Which lead faster execution of your code.
Really pick anyone . I would suggest php if you are not comfortable with javascript yet, as it is really easy to get started with php and then groom your javascript knowledge till you feel more comfortable with it then you can try out Nodejs
I don't think there is something in php that you can't do in node and vice versa. So choose the one you are comfortable with.
But I guess the way they handle requests are different. For instance node handles requests concurrently whereas php spawns a separate instance for each connection.
Also for php you will need apache or nginx.
Node has npm, php has its own libraries/utilities etc. Php 7 has also huge performance benefits compared to 5/6 etc.
Personally, although my main language is javascript and I work with node, I like php's syntax better, its just sugar. I also have strange feelings having javascript on server side, maybe it's just that I'm a salty neckbeard.
There is no right or wrong here. Look at both languages, play with them a little, choose the one that feels right for you.
I know both languages and i am also comfortable with both. the real problem that m facing is deployment. Can i host my node js application on hostgator?? If not then where can i host my node js app.
Natalia N
Marketing specialist
It's better to compare PHP and Node.js in certain use cases. For example, PHP is better for standardized solutions such as a blog, news site, landing page. Also, PHP is better for CPU-intensive application development. On the other hand, Node.js will be a better choice for real-time service. Here are other Tips for PHP and Node.js projects