Which technology to use when tapping the server?

When you add a record in the database need to update data on the front. Server-side codeigniter. As I understand it, you need to create a second thread. You need to use promises?
April 7th 20 at 10:56
1 answer
April 7th 20 at 10:58
Solution
If the data in the database throw to the server via ajax from the frontend, then the updates expect the same response (for example success or error, etc.), when, on the basis of the data already and change the front contents. You can also using fetch:
fetch(url, options)
 .then(response => response.json())
 .then(result => /* process the result */)
the problem is that the record in the database will not be with this app. Then I see or do either an Ajax request for example every 10 seconds and wait for the respons, or as something to hang on the server thread which will front to announce that in the database there was a record - Amya28 commented on April 7th 20 at 11:01
@Amya28, Another question - if you need to synchronously update data to all clients ;)... Here is a backend on node bunch, or broadcast request interval to the server and in fact the data changes to change on the clients - Johnny_Weissnat commented on April 7th 20 at 11:04
@Johnny_Weissnat, there is no node. Used codeigniter and rewrite node.js no one will, and time consuming. But if a separate thread and in the background to listen? - Amya28 commented on April 7th 20 at 11:07
@Amya28not understand how to "hang on to the server thread". The PHP script essentially each script has its own run time, then "dies", and query and stream. My simple and inexpensive option is to periodically poll the server :) - Johnny_Weissnat commented on April 7th 20 at 11:10
@Amya28, you can install websocket - type socketo.me

It seems to have rewritten under CodeIgniter https://packagist.org/packages/takielias/codeignit... - sally.Legros25 commented on April 7th 20 at 11:13
@Amya28, when talking about multi-threading in JS, then it is not (is emulation). JavaScript runs on single thread processing - Johnny_Weissnat commented on April 7th 20 at 11:16
@Johnny_Weissnat, it is. Tried on php. Using time Connection: close
Connection: keep-alive, but in parallel, stops the execution of the script on the front - Amya28 commented on April 7th 20 at 11:19
@sally.Legros25, thanks, looking - Amya28 commented on April 7th 20 at 11:22
@Amya28, essesno, the answer came back. You have script on the front have to constantly work, set the interval.
let timerId = setInterval(() => alert('tick'), 2000);

or a recursive setTimeout - Johnny_Weissnat commented on April 7th 20 at 11:25
@Johnny_Weissnat, but if web workers ? - Amya28 commented on April 7th 20 at 11:28
@Amya28, what's the point? why don't want to use a range query? The application of high load or long running query? Using web workers can try, but how long will it take for implementation? Again, the principle remains the same - a cyclic queries in the Beck. Beck in PHP itself does not return until it asks, and to increase the script execution time and lead it in a thread is inappropriate. - Johnny_Weissnat commented on April 7th 20 at 11:31
@Johnny_Weissnat, well, thanks for the explanation - Amya28 commented on April 7th 20 at 11:34

Find more questions by tags PHPJavaScript