javascript - Server Side Broadcast Update PHP -


I want to create an application that will automatically broadcast notification (u) to a user when data changes on the server So far, I just know one way of doing this i.e. using this function by using JQ setInterval , every client requests data via AJAX from the server, and asks Whether something has changed or not.

The weakness of this method will be to send packets to every customer at all specific time intervals, so my server receives a large data packet. It is so frustrating to manage the server whether Jacob setInterval

Apart from this there are no alternatives for you, an option for you, you can use an AJAX request on the server The server side goes into an eternal loop. Use the SO function to avoid memory overload, by checking each time, if something has changed. If so, break the loop and return the data. Send immediate requests to the client side.

After some research it is called "Ajax Long-Polling Request".

The PHP code will look something like this:

$ prevHash = $ _GET ['hash']; While (true) {$ currHash = GetHashFromTable ('myTable'); Break ($ ​​prevHash! $ $ CurrRowCount); Sleep (3); } $ Response [0] = GetDataFromTable ('myTable'); $ Response [1] = GetHashFromTable ('myTable'); Echo json_encode ($ response); Update

Voting is not the best option for long If you want, see this answer:


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -