Marko Morris
Marko Morris

Reputation: 141

A Little Explanation About Chat Application

I am planning to create a chat application that will be used by thousands of users. Initially I have done a lot of tutorials on the net and read many things about PHP and MySQL chat applications. During this search I have come across many people saying that chat applications in PHP are good for thousands of users. Most of them suggested using NodeJS. The problem I have here is that none of those posts stated why NodeJS is good.

From all the PHP chat tutorials I read, it seems that during the chat sessions between two users, the messages that they are exchanging are sent forth and back to the database. My questions are:

  1. In NodeJS, are the messages not sent forth and back to the database?
  2. Does NodeJS save the chat messages in memory or something like that?
  3. How does it do it differently from PHP and MySQL?
  4. Or does NodeJS not use databases at all?

Can someone help me to understand how chat applications work in NodeJS?

I am not asking for code snippets. I want explanation in words. I know there are many tutorials around about NodeJS but am asking specifically concerning chat applications. Your explanation will help me to understand certain things better.

Upvotes: 4

Views: 208

Answers (1)

Madara's Ghost
Madara's Ghost

Reputation: 175017

The main difference between PHP and Node.js, is that Node.js supports multithreading, and events.

In PHP, you'll have to periodically ping the server for new messages, each user would need to do so.

In Node.js, you can implement a smarter solution. Where the client ping the server once, and only gets a response when a new message is received. After that, you ping again.

That reduces server-load immensely, and allows you to handle more users simultaneously.

Upvotes: 3

Related Questions