Connecting PHP Sockets to a TCP Server

I have the following script:

I have a predefined program that provides a JSON interface to which I can connect using a socket connection. Since I want to integrate this interface into my web application, I am trying to use PHP sockets for communication between server and client. The message is bidirectional, which means that my PHP client sends requests to the server, and the server also sends requests to my PHP "client". I have no problem connecting my PHP and JSON interface. The only problem is that since I have to wait for requests on the PHP side, I have to run it in an infinite loop. I want to "respond" to some of the answers and requests that I get somewhere in my web application without this infinity loop.

My question is: is there a good way to create a single php file that can:

  • create your own socket server so that I can send stuff from my web application to it without getting stuck in an endless loop
  • the material that 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 an NFC card reader that provides me with functions and card information (uniqueid) and connects to my network. The JSON server sends me a request for a "detected card" and I respond with "resolved" or "not resolved". (There the loop of infinity does not matter)

: -, "uniqueid" , . : - " " - - - uniqueid

- JSON. - PHP, JSON.

, .

+4
1

, . Ratchet . , . Websockets.

, , .

. fooobar.com/questions/11752/... ( -).

+1

All Articles