there is such a task, in PHP, write a socket server, which will receive some requests, and transfer them to another server, over an already established socket connection. Separately, both tasks are solved without problems, the problem is that both the server and the php client start an infinite loop, and accordingly, if you start the client first, then it will not come to the server. Perhaps there is some way to run the client in the background, and have access to it?
1 answer
There is only one way out - to write separately and use the data bus. For example redis pub / sub, or write a crutch on mysql.
Well of course in cli mode to run everything.
To simplify the code, use ReactPHP, as well as describe the conditions and signals for quitting the application or restarting it. For this, for example, the Symfony\Cache component is very useful.
In any case, these are two different processes and they should work asynchronously.
- The situation is aggravated by the fact that I need to operate objects between the client and the server, and thanks for the tip! - Artem Bondarenko
- In this case, you need to edit the architecture. And objects can be serialized - Maxim K
- In principle, any communication of services (and you should have at least two demon services) between each other is a string one - Maxim K
|