I have the following scenario:
I have a given program which provides a JSON interface to which I can connect using a socket connection. Since I want to integrate that interface into my web-application, I'm trying to use the PHP sockets for the communication between server and client. The communication is bidirectional, which means my PHP client is sending requests to the server and the server is also sending requests to my PHP "client". I have no problems with the connection between my PHP and the JSON interface. The only problem is, since I have to wait for requests on the PHP side, I have to run it in an infinity loop. I want to 'echo' some responses and requests i get somewhere into my web-application without having that infinity loop.
My question is, is there a good way to create one php file which can:
- create an own socket server so I can send stuff to it from my web application without being stuck in an infinity loop
- the stuff I sent to it can be redirected to the JSON server
- the response I get from my JSON server redirecting to my web application
Use case I have a solution for: I have a NFC card reader which provides me the functions and informations of a card (uniqueid) and it's connected to my network. The JSON server sends me a request on "card detected" and I respond with "allowed" or "not allowed". (There the infinity loop doesn't matter)
Use case I don't have a solution for: I have my web application open and I want to write the "uniqueid" parameter into an input field to assign that card to a person. I want to do it this way: - Click a button "assign card" - Hold card over the card reader - Write uniqueid into input field
I don't want to make a direct connection from the web application to the JSON server. I want to make a temporary connection from the web application to the PHP server which has a permanent connection to the JSON server.
I hope this is understandable.