A
A
Alexander Sharomet2015-04-25 17:42:27
PHP
Alexander Sharomet, 2015-04-25 17:42:27

How to use php to pause script execution?

Hello.
The following question arose: I have a chat, messages in it are updated using the javascript (ajax) setInterval command, for example, every 2 seconds. The problem is that the user can see this script and can simply change the parameters by checking for new messages every 0.2 seconds, for example, which will naturally have a bad effect on the database. How can this situation be corrected. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petrov, 2015-04-25
@sharomet

Make it impossible to change. For example, we use setTimeout , and we pass the time of the delayed call in the header of the message from the server.
This will not only solve the described problem, but also allow you to control the frequency of requests depending on the load on the server.
In general, for organizing a chat, it has long been recommended to look towards WebSockets .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question