Posted by instant messenger: http://rsdn.ru/forum/flame.comp/6042249.1 It works on ordinary HTTP requests. Now I try to understand how it should work in the correct version.

I got an understanding of what to do with a TCP connection, the server authorizes it, signs up for updates and sends data to the socket when it appears.

I understand web-based websites and begin to understand that you cannot make any subscriptions for them. That is, it is the same HTTP, but without breaking the connection.

So how should a messaging system be built to be more optimal?

  1. In the mode of responding to client requests, plus send notifications about new events.
  2. In the mode of responding to client requests, but the client must constantly send a request for updating data.

The first option seems more optimal, but it will require more cunning logic. Is it implemented in php? The second option is simpler, but periodic requests, say every 2 seconds, this does not seem to be the best solution.

  • Some kind of misunderstanding. Web sockets are sockets, and no subscriptions are possible. (True, I did not understand how. But on several sites I observed this personally.) - andreymal
  • Yes, actually, on StackOverflow this is exactly the case :) i.imgur.com/YpYygDN.png - andreymal
  • @mikelsv, but on what did the backend, if not the secret, implement phpDaemon, Ratchet or your bike? "Now: request -> apache -> php -> mysql" Hmm, I am confused by this bunch. If I am not mistaken, Apache cannot proxy websocket, unlike Nginx ( nginx.org/ru/docs/http/websocket.html ). Wow, learned ( httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html ) And yes, since when did MySql (libmysql) learn how to work asynchronously, if it is not mysqlnd? - romeo
  • The fact of the matter is that now I have no websockets. I just understand how to fasten them. Ideally, I want my bike. - mikelsv
  • "Ideally, I want my bike" A very big mistake! Out of the box, PHP does not have to be parallel and asynchronous without dancing with a tambourine - "PHP is created to die" ( habrahabr.ru/post/179399 ). But there are rays in the dark kingdom: Korutin ( habrahabr.ru/post/164173 ) and WSGI ( habrahabr.ru/post/250055 ). In other words, the application or application server should work as an event loop. Within this cycle, blocking by third-party services should not occur, for example, a DBMS, i.e. everything should work asynchronously. In some cases, resort to queuing services (MQ). - romeo

0