PHP with real-time updates

1

I want to start a project, and studying and doing surveys have seen the need to update in real time. For example:

I have a login screen, which shows the companies that telemarketers have to call. Suppose that the same company appears for the two telemarketing's on the same screen or in the same listing, when the first telemarketing clicks on that company, that company has to disappear from the screen of the other automatically.

It really would have to be an update in real time, I already researched and did not find much relevant.

I wanted to hear from you if PHP has support for this, and if someone has already gone through something similar and how it worked out. Feedbacks on how to do this are accepted.

    
asked by anonymous 15.03.2017 / 13:02

1 answer

2

Currently, the most recommended way to do this would be by using WebSockets for a permanent client-server connection.

Unfortunately, WebSockets are not yet widely supported by all browsers (basically just Chrome and the latest versions of other browsers). So there are alternatives like Long Pooling , which I used in a project recently.

Long Pooling basically consists of "asking" the server at regular intervals if there is any new information, as in the example:

(function poll(){
   setTimeout(function(){
      $.ajax({ url: "server", success: function(data){
        //aqui você faz seu código...


        //prepara o próximo poll recursivamente
        poll();
      }, dataType: "json"});
  }, 30000);
})();

The function above, contacts the server regularly (every 30 seconds) to request information.

You can look for tools that encapsulate the existing techniques of this type of technology, that make available to you the most appropriate, according to the browser. I do not know of such tools to develop in PHP, but for ASP.NET, there is the SignalR

    
15.03.2017 / 13:13