Which one to choose for a chat application? PHP or NodeJS?

I’ve been reading articles since morning an I am completely lost. Lots of people say that using PHP isn’t a scalable solution for a chat application.

Is that true? If it is, can you show me an unbiased article or share your thoughts on that?

Additional question : Can NodeJS be an alternative to PHP? I literally don’t know anything about it right now.

Thank you!

Actually, you can use them together.
I would recommend PHP for HTML generation, users management and other ordinary tasks and NodeJS for the server side of chat itself (broadcasting messages between users in real time). It is much simplier to do many typical web things with PHP while NodeJS has a great power for real-time applications with web sockets (yes, you can use web sockets in PHP too, but it isn’t that simple).

Here is some good points

What’s wrong with EJS, Jade, or Handlebars?

I don’t think it’s simpler to do those things with PHP at all. (personal preference) It’s just as simple to use Node.js and if you’re building as a Single Page Application, then I find it to be much easier to build restful services in Node.js over PHP.

The main argument there is that PHP doesn’t need a template language so that you can mix business logic with your views. Where as there are plenty of good reasons to keep your business out of your views and is widely considered bad practice, even in PHP.

Okay, but I read that I can’t embed nodejs code into my php files. Imagine that there is a web page consists of different parts (content management, chat, feed), can I use nodejs for only chat part or do I have to convert all my project into node and have to use a template engine like Jade?

I want to use PHP for most of the time and I am thinking of using nodejs for chat feature of the website. Can I do something like that?

I’ve looked into those template engines but they look very ugly. (No offense)

No… not Node.js. The point of Node.js is that it’s ran on the server. You can use JavaScript in your HTML to talk to your Node.js server. Your HTML can be rendered by PHP or it can just be static .html files.

You can have Node.js and PHP running on the same server. They will just talk on different ports.

You don’t have to use Jade, I don’t really like it either. I prefer EJS, it’s more like traditional template engines.

There are others too:

http://garann.github.io/template-chooser/

Yes, if that’s what you’re comfortable doing. Node.js can just be your websocket chat server, you don’t have to use it for the actual site.

It’s kinda complicated to me, so I’ll ask one more question.

So I don’t need to start from scratch, I can keep developing my website with PHP, all I need is to create a seperate nodejs application for chat module (or any realtime feature) and use javascript in my php file to talk to it when it’s needed, is that correct?

Thanks, by the way.

Yes. Exactly.

Have you looked at this tutorial yet, using Socket.io?

I suggest doing that tutorial, then taking a look at their slightly more complicated Demo app:

code: https://github.com/Automattic/socket.io/tree/master/examples/chat

2 Likes

Nothing wrong at all. But PHP looks more “essential” for such kind of tasks. That is just my private opinion, not the final truth.

Why have you decided this is the main argument? I can’t see where author tells that. This is just one of arguments (not the best one, because I completely agree with your point about logic and view separation). Anyway, that article isn’t about “why PHP is better”, it’s about pros and cons of each tool.

Well, maybe not the main but one of the top and it seems to be a reoccurring theme throughout the post, since the author seems to think it’s OK. lol

Really, all the arguments are kind of weak on both ends. The only one that even make sense are “Simplicity”, “Complexity”, "Service calls are thinner ", “JSON”, and “Raw Speed”. The rest are either flat out wrong or don’t make sense. Mostly just wrong.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.