PHP with real-time updates

Asked

Viewed 2,146 times

1

I want to start a project, and studying and doing surveys saw the need for updating in real time. As for example:

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

It really would have to be a real-time update, I’ve done some research and I didn’t find much relevant.

I wanted to know if PHP has support for this, and if anyone has experienced something like this and how it has solved. Feedbacks on how to do this are accepted.

1 answer

2


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

Unfortunately, Websockets are still not widely supported by all browsers (basically only Chrome and the latest versions of other browsers). So there are alternatives, like Long Pooling, I used on 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 above function, contact the server regularly (every 30 seconds), to ask for information.

You can look for tools that encapsulate the existing techniques of this type of technology, which make available to you the most suitable, according to the browser. I don’t know such tools to develop in PHP, but for ASP.NET, there is the Signaler

  • I get it.. I’ll analyze . The reason I want to do it in php is because I have little time , and learning another language will be difficult.

  • It’s perfectly possible to do it in PHP. PHP is at the same level as C#, and it was in C# that I did my project

  • That comment reassured me a little rsrs.. I’m thinking of using Long Pooling or Websockets, but like you said Websockets don’t have much support. Would it be a good idea if I forced users to use a more up-to-date browser ? Taking into account that this product theoretically would not be very popular rsrs. But I will analyze!

  • Some websites recommend using more up-to-date software for "better experience". But you should not force the user to use something, it is bad practice. You can implement simple Longpooling, like the one I exemplified, and in the distant future, swap the technology if you want.

  • True. But what the difference in performance between Longpooling and Websockets ?

  • 1

    Web Sockets keep the client-server connection open permanently, and can cause information to flow on both sides. In other techniques, either you keep an infinite loop in the request, to increase the time of it and make it wait (Long Pooling), or you keep asking sporadically for information, like this example I gave you. But I can not say what is the difference in performance, but I think that Websockets has advantage, since you do not need to keep making requests

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.