You can do it with non-blocking socket and long polling technique.
The workflow is something like this.
- PHP connects to Modem with a non-blocking socket.
- Web client sends a long polling http request which times out after 5 or 10 minutes.
- PHP made the incoming client connection as non-blocking. This way PHP adds every client to a queue.
- PHP iterates over each of the clients and modem and check if something could be written or read.
- if there is something to read from Modem it reads and process. If necessary message is written to Webclient socket.
- Same as step 5 but goes from web client socket to modem socket.
- Do any additional work.
- GO to step 3.
I had a similar situation months ago. I had to keep web sessions in PHP and there was another server which PHP was connected too. Couldn't finished it. Later I had to move to Python for this.