Replies: 1 comment
-
|
There are various options, depending on what client is doing (that is not a reaction to incoming messages from server). If the action is limited and not triggered by external input, you can use the onTick listener. This callback will run periodically, independent on incoming messages. But it is blocking server read, so you do not want to run loops or too complex code here. If you need a more flexible setup, I would recommend using a queue as an intermediate between WebSocket client and the internal code (running as separate scripts). When the internal script need to push to server, it writes message to the queue. Then the WebSocket script can use onTick callback to read the queue and push to server. There are advanced asynchronous queue servers such as RabbitMQ but you can also use a custom database to store the queue. You might also be able to set something up using the PHP Fibre feature or an app server like Swoole which are coroutine implementations, allowing you yo switch code execution context. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm sorry for asking this, I'm still rookie with PHP and this technology of Web Sockets.
I want to:
1 and 2 I know how to do. But third one I don't know how to and dunno is it possible at all.
For example,
I established connection, listen to what server sends, and in one time I want to use the same connection to send data back to server without establishing new connection. For now how I use it:
But because of this, I think I use websocket wrong.
Beta Was this translation helpful? Give feedback.
All reactions