Is this the most effective way to make a chat?

So, I use php, mysql and jquery to create group chat. Here is what I did:

  • The user receives new messages every second.
  • I am returning a cached file through jquery. If there is no cached file, I pull out the messages from mysql, cache it and show this file to the user.
  • If the message is a member message, the cached file is deleted.

Is there anything I can do to make it more efficient? I think this is the best solution, right?

+4
source share
2 answers

you should check out Node.js ; This is a very effective way to continue such a chat project.

cf, for example, is a chat demo .

Node.js is a powerful infrastructure for real-time web applications. The server-side application is written in Javascript so that you can present an event for the exchange of codes between the client and the server (you could share classes, exchange templates ...)

+1
source

UPDATE: A very similar question. Ajax chat bandwidth efficiency

Instead of every second, increase the delay if no messages are sent, therefore, if no message is received within 1 second, execute the following request in 5 seconds, if no message is received after 15 seconds, and therefore by ... until you receive the message .

You might want to check out jQuery periodic updates that do this and some other options.

+1
source

Source: https://habr.com/ru/post/1343042/


All Articles