PHP event listener

I want my web server to notify me through a php page when an event occurs on another TCP server with which the PHP page successfully connected via a socket. The event is like a TCP server wants to send a message to a web server, etc. Is there any way to accomplish this and / or any links on how to do this?

+3
source share
1 answer

Of course:

$fp = fsockopen("tcp://example.com", 8888) OR die("could not connect");
while (!feof($fp)) {
    $pc = fread($handle, 8192);
    if ($pc === false || strlen($pc) == 0)
        break;
    //a new packet has arrived
    //you should collect the read in a variable and wait
    //for another packet until you know the message is complete
    //(depends on the protocol)
    collect_in_result($pc);
    if (message_is_complete()) {
        if (check_event()) {
            //take action
        }
    }
}
+2
source

Source: https://habr.com/ru/post/1749906/


All Articles