Optimal the implementation of the chat?

Tell me, if the optimal and effective implementation of the chat:
1. Structure: a index.php it in the sidebar include chat.php. In сhat.php the layout of the chat entry form messages, and include chat-messages.php. In chat-messages.php accordingly, the PHP code of the output messages from the database
2. Also in chat.php ajax request to update the chat without refreshing the page (url: 'check-chat.php',). Update interval - the second half.
3. Displays the last 100 messages

The following questions arise:
1. Much of these requests every six seconds to load the database?
2. This optimal realization in General?

Thank you all
PS. only recently started to understand php, do not know much, so don't scold
June 10th 19 at 15:45
6 answers
June 10th 19 at 15:47
Now open this page in 20 tabs and look at the load.
If you want a chat then look away Websockets and not Ajax
June 10th 19 at 15:49
Better look away websocket
If the chat will flood at the same time 50 people, I think the host will fall
June 10th 19 at 15:51
If it's not production, but let's say, educational-entertaining project, that will go. You can increase the interval to 5 sec, and our database to choose more time time of the last received message, this will reduce the load. The time necessary to send in the request to the server. All read by the recipient (i.e., sent in response to Ajax request) the recording of the chat is flagged in a separate field in the table(e.g. `readed` = 1) and not further out. Ideally, to rewrite the sockets for Ajax intervals are not the best method of implementation.
June 10th 19 at 15:53
Try to pass ID of the last message in the chat and get only those texts that are more recent and not 100 every time
Change the format to JSON, just 2 vectors(arrays)-nicknames and messages.
a second switch for 5 seconds
and all
June 10th 19 at 15:55
And best of all use comet server, it is convenient and productive, look https://comet-server.comI have done a project with it, everything works fine and is implemented simply, documentation is detailed, as a SaaS service using or your server to put. All for free :)
Here are a couple of examples of how to use codemarks.ru/php/ispolzovanie-comet-servera-dlya-s...
June 10th 19 at 15:57
You have no the system is not optimal. She will put you database in a dozen users online (at least 2 dB query per second per person, for 10 people it is 20 requests per second)
These questions and answers should help

Find more questions by tags AJAXMySQLjQueryPHP